C Object-like Macros

Intermediate
6 min read
Updated: Nov 2026
1 example

What Is Object-like Macros?

An object-like macro has no parameter list, such as #define MAX_USERS 100. They name constants, strings, and short expressions. When the replacement is an expression, wrap it in parentheses so operators around it cannot change its meaning.

Remember
#define MAX_USERS 100
#define VERSION "1.0"
#define TWO_PI (2 * PI)       /* parenthesized expression */

Cheat Sheet

Keep these facts handy while you work with Object-like Macros in C.

TopicDetail
ConstantsNumbers, strings, characters
ExpressionsAlways parenthesize
TypesNone: plain text
ScopeUntil #undef or end of file

C Examples

Compile each example with gcc file.c -std=c11 -Wall -o out. Next: Function-like Macros.

Example 1 — Why parentheses matter

Compare an unparenthesized and a parenthesized expression macro.

C
#include <stdio.h>

#define BAD  1 + 2
#define GOOD (1 + 2)

int main(void) {
    printf("BAD  * 3 = %d\n", BAD * 3);
    printf("GOOD * 3 = %d\n", GOOD * 3);
    return 0;
}

How It Works

  1. BAD * 3 becomes 1 + 2 * 3, which is 7.
  2. GOOD * 3 becomes (1 + 2) * 3, which is 9.
  3. The preprocessor does textual replacement; it does not evaluate first.

Edge Cases & Pitfalls

Check these before relying on Object-like Macros in real programs.

type

No type safety

#define SIZE 10 has no type. Use const size_t or enum when type checking helps.

redef

Redefinition

Redefining a macro with a different value is an error or warning. Use #undef first.

Key Takeaways

  • Parenthesize expressions.
  • UPPER_CASE names.
  • Prefer enum for integer groups.

One line: An object-like macro has no parameter list, such as #define MAX_USERS 100.

Frequently Asked Questions

A macro defined without parameters, which the preprocessor replaces with its replacement text wherever the name appears.
It signals to readers that the name is a macro, not a variable, so it may behave differently, for example by evaluating arguments multiple times.
Continue with "C Function-like Macros" next. Macros with parameters, stringizing (#), and token pasting (##). The C Preprocessor hub lists every topic in order.

Next: Function-like Macros

Macros with parameters, stringizing (#), and token pasting (##).

Continue →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful