What is purpose of #defs inside a strcuture

P

parag_paul

Isnt is so that whenever the compiler reads an #def it will replace it
with letter by letter on the place is see the macro, so what is the
purpose of keeping #defs inside a structure,


struct A{
#define A_list(e) (e)->list()


}
 
B

Ben Pfaff

Isnt is so that whenever the compiler reads an #def it will replace it
with letter by letter on the place is see the macro, so what is the
purpose of keeping #defs inside a structure,

Macros do not have to be defined inside a structure.
struct A{
#define A_list(e) (e)->list()

Perhaps this macro is defined inside the structure to indicate
that it is used in conjunction with the structure.
 
S

santosh

Isnt is so that whenever the compiler reads an #def it will replace it
with letter by letter on the place is see the macro, so what is the
purpose of keeping #defs inside a structure,


struct A{
#define A_list(e) (e)->list()


}

I can only think of one reason: to indicate to anyone reading the code
that that macro is meant only to be used with actions on objects of the
enclosing struct type.
 
K

Keith Thompson

Isnt is so that whenever the compiler reads an #def it will replace it
with letter by letter on the place is see the macro, so what is the
purpose of keeping #defs inside a structure,


struct A{
#define A_list(e) (e)->list()


}

It makes no difference where you define a macro, as long as it's
defined before you try to use it. In this case, it's defined inside
the struct definition because it's logically associated with the type.
It's just for documentation, not for functionality.
 
E

Eric Sosman

Isnt is so that whenever the compiler reads an #def it will replace it
with letter by letter on the place is see the macro,

Almost: The replacement is token by token, not letter
by letter. (Even that isn't quite right: Each occurrence of
"token" really should be "preprocessing token" -- but the
phrase "preprocessing token by preprocessing token" doesn't
come trippingly on the tongue, does it?)
so what is the
purpose of keeping #defs inside a structure,

struct A{
#define A_list(e) (e)->list()


}

Documentation, most likely. The placement of the #define
directives is a hint to someone reading the code that the
macros are to be used in connection with a `struct A', and
not on their own or with some other type of object.
 
P

parag_paul

Almost: The replacement is token by token, not letter
by letter. (Even that isn't quite right: Each occurrence of
"token" really should be "preprocessing token" -- but the
phrase "preprocessing token by preprocessing token" doesn't
come trippingly on the tongue, does it?)




Documentation, most likely. The placement of the #define
directives is a hint to someone reading the code that the
macros are to be used in connection with a `struct A', and
not on their own or with some other type of object.

Thank you all, that helps

Was reading some legacy code and was thinking that it was some old
trick out of the old bag
-Parag
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,438
Messages
2,571,699
Members
48,796
Latest member
Greg L.
Top