   #defining (?)
  I don''t really know what to call this so I''ll bring en example:suppose you have something like this (the example below is pure fiction):Global->Object->Properties->Type->FlagsYou have a lot of properties in class Global so you''re looking for a way to truncate the expression. What I''d like to do is to use a simple define, such as:#define Object-> Global->Object->The above code won''t compile, though because the compiler expands it to this:#define "Object" "-> Global->Objects->"I added the quotes for clarity. Defining the Object without the trailing arrow isn''t good either because it can lead to problems with the word Object in the middle or beginning of an irrelevant variable name.I do recognize that what I''m trying to do is very error prone (if a variable name ends with the word Object and points to a nested item, the replacement will produce an error), but I''m really beginning to have a problem with so many (4 or more) levels of nested references.Any ideas? 
  You could use references, I suppose.eg:cObject &Object = Global->Object;John B ;  Instead of a #define, use an alias pointer: // this is badGlobal->Object->Properties->Type->Flags = ...;// set up an alias pointer:ObjectType *alias = Global->Object;// and use it to access stuff:alias->Properties->Type->Flags;It has the exact effect you''re looking for, is much safer than #defines and as an added bonus, this method will provide you with an extremely small speed boost because you''re not dereferencing multiple things all the time.-Auron ;  Or#define Object Global->Object ;  JohnBSmall and AP: Yeah, I could do that, but that might actually be even more confusing. I generally have up to 4 or five such kind of "deep references" in one function so instead of a speed boost I might end up with a speed loss (memory allotment and cleanup for a new variable each time the function is called).Making these aliases gloabl would most likely help, but that would in my case produce at least 20 new globals...ToohrVyk: consider this:#define Object Global->Objectmain(){//bla-blaMyObjectManager->Flush();};quote:I generally have up to 4 or five such kind of "deep references" in one function so instead of a speed boost I might end up with a speed loss (memory allotment and cleanup for a new variable each time the function is called).Uh, so you're saying stack allocation of these variables is going to slow you down? Get a grip man. Write the most clear thing and profile later! No need for #define's in this case. Something tells me this portion of the code isn't speed sensitive, too. Why else would you be assigning so many things?   [edited by - antareus on August 16, 2003 4:54:20 PM];quote:Original post by Crispy  ToohrVyk: consider this:#define Object Global->Objectmain(){//bla-blaMyObjectManager->Flush();}  What about it? I see no problems there.;  I think you should consider redesiging your app... ;  It''s no wonder the preprocessor is turning#define Object-> Global->Object->into the string  "Object" "-> Global->Objects->"-> is not part of a valid name. Try something like this#define MYMACRO(g) g->Object->Memberand then use it like so MYMACRO(Global);Another variation #define MYMACRO(o, m) Global->o->mand use it like soMYMACRO(Object, Member);and another#define MYMACRO(g,o,m) g->o->mand like soMYMACRO(Global, Object, Member);Remember, the preprocessor performs a text substitution on the code and the resulting substituted text is what gets sent to the compiler. so MYMACRO(Global, Object, Member); ends up looking likeGlobal->Object->Member;before it gets compiled. If for some reason there is no Object member of Global, or no Member memer of Object, you''ll get a compile time error that might not easily be tracked down. Consult the docs for your compiler regarding what kinds of command line switches are available. One of them should direct the compiler to dump the preprocessed code out to file. That code can be examined to determine whether or not a macro has substituted text as intended or not. ;  Look Crispy, don''t use "#define" for this. It has already caused problems for you and it will continue to cause problems. The smart thing to do is to follow JohnBSmall''s or Auron''s suggestion. It will not slow your code down and it might even speed it up. It will be less confusing than a bunch of "#defines". 