selva
selva

Reputation: 97

Where macros variable created? and size of the variable?

I have doubts about macros, When we create like the following

      #define DATA 40

where DATA can be create? and i need to know size also?and type of DATA?

In java we create macro along with data type,

and what about macro function they are all inline function?

Upvotes: 0

Views: 72

Answers (4)

user1508519
user1508519

Reputation:

Macros are literally pasted into the code. They are not "parsed", but expanded. The compiler does not see DATA, but 40. This is why you must be careful because macros are not like normal functions or variables. See gcc's documentation.

A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro. There are two kinds of macros. They differ mostly in what they look like when they are used. Object-like macros resemble data objects when used, function-like macros resemble function calls.

You may define any valid identifier as a macro, even if it is a C keyword. The preprocessor does not know anything about keywords. This can be useful if you wish to hide a keyword such as const from an older compiler that does not understand it. However, the preprocessor operator defined (see Defined) can never be defined as a macro, and C++'s named operators (see C++ Named Operators) cannot be macros when you are compiling C++.

Upvotes: 2

NPE
NPE

Reputation: 500673

Macros are essentially text substitutions.

DATA does not exist beyond the pre-processing stage. The compiler never sees it. Since no variable is created, we can't talk about its data type, size or address.

Upvotes: 3

uhs
uhs

Reputation: 848

Preprocessor directives like #define are replaced with the corresponding text during the preprocessing phase of compilation, and are (almost) never represented in the final executable.

Upvotes: 0

Chinna
Chinna

Reputation: 4002

macro's are not present in your final executable. They present in your source code only.macro's are processed during pre-processing stage of compilation.You can find more info about macro's here

Upvotes: 0

Related Questions