Macros can suck my... something hairy

This is a discussion on Macros can suck my... something hairy within the C++ Programming forums, part of the General Programming Boards category; You can't win. I hardly ever use the beggars but when I do everything goes t*ts up. Basically I've got ...

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    Macros can suck my... something hairy

    You can't win. I hardly ever use the beggars but when I do everything goes t*ts up.

    Basically I've got a set of headers I want to use across several DLL's (so several projects) so I've got this directory structure:

    Code:
    ROOT ------ NothDebug
                    |
                    - NothKernel
                    |
                    - SharedLib
                    |
                    - Runtime
    So ignore all of them except SharedLib. Basically it includes several headers and to save me typing "..\SharedLib\Singleton.h" (for example) I'm trying to get a macro like this to work:

    Code:
    #define SHARED(h) "...\SharedLib\" ## h
    Of course I get "newline in constant" so I replace it with "...\\SharedLib\\" which doesn't work because now it can't find the header "..\\SharedLib\\Singleton.h".

    I use it like this BTW:

    Code:
    #include SHARED(Singleton.h)
    After trying to put #include in the macro which didn't work.
    Help! Save my fingers!
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    Is it to do with the fact you've got 3 dots before your \\SharedLib instead of 2? In the W2K dosbox, typing "cd ..." causes the prompt to remain in the same directory.

  3. #3
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    I haven't got 3 dots in my editor. Must've been a typo as I copied it across. That'll teach me to use copy and paste next time
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    I'm pretty sure macros aint dynamic enough to do what you want...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Yeah I've given up on it. Stoopid macros.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,311
    Most compilers support some way of specifying a search path for #include files. For example, unix compilers (which include proprietary compilers from sun, sgi, etc etc as well as freely available compilers like gcc) accept a command line argument "-I" which allows specification of an include path.

    For example, gcc -I ../SharedLib <other options> file will provide a means of achieving what you want. The difference is that the magic to make it happen will need to be in build scripts or makefiles, not in your source code.

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    2,040
    Code:
    #define SHARED(h) "...\SharedLib\" ## h
    Correct me if I'm wrong, but shouldn't this be this:?
    Code:
    #define SHARED(h) "...\SharedLib\" #h

    ## is used to combine two symbols into one.
    # is used to convert a value into a string.
    Last edited by King Mir; 04-24-2006 at 09:36 PM.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Order of execution of preprocessor macros
    By DL1 in forum C Programming
    Replies: 2
    Last Post: 04-02-2009, 06:52 PM
  2. Macros inside of macros
    By Chewie8 in forum C Programming
    Replies: 2
    Last Post: 02-24-2008, 02:51 AM
  3. Macros vs Inline Functions
    By vb.bajpai in forum C Programming
    Replies: 4
    Last Post: 08-02-2007, 11:51 AM
  4. template fn replacements for msg macros
    By Ken Fitlike in forum Windows Programming
    Replies: 17
    Last Post: 10-30-2002, 06:55 AM
  5. Why america sucks
    By muttski in forum A Brief History of Cprogramming.com
    Replies: 138
    Last Post: 04-10-2002, 11:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21