Results 1 to 7 of 7

Thread: [RESOLVED] Impossible? - #include and #define

  1. #1

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Resolved [RESOLVED] Impossible? - #include and #define

    OK this is going so sound weird but bear with me, there is a very good reason for wanting to do this...

    Code:
    #define PREFIX myfolder/proto_
    
    //this one is defined elsewhere... and will be redefined several times during the app
    #define MIDDLE http
    
    #define SUFFIX .h
    How is it possible to get the precompiler to generate this...

    Code:
    //desired result...
    #include "myfolder/proto_http.h"
    If it makes any difference, I'm using gcc (version 4.0.0 20050519 running on Red Hat Linux 4.0.0-8).

    I have fairly strong suspicions that this is not possible without using an external process during the makefile but I wanted to do it all within the C files.

    The main problem I'm having is getting around the strictness of the #include directive which won't let you "cat" "strings" "together" "like" "this".

    It would save me a huge load of maintenance time if I could get this working because it lets me reduce 99% of a very large switch{} block into about 5 lines in a header file.
    I don't live here any more.

  2. #2
    Addicted Member Kal-El's Avatar
    Join Date
    Jun 2007
    Location
    Fortress of solitude
    Posts
    179

    Re: Impossible? - #include and #define

    Dude...I think that's impossible

    «Source Code»«plugins»«skin»«fav apps»«Winamp en español»«Nsis en español»
    So what if your signature move is driving a tractor? I think it's adorable. - Lois ("Crimson")
    Don't forget to when your question is resolved ...and the people who help

  3. #3
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403

    Re: Impossible? - #include and #define

    This is the closest I was able to get...


    Code:
    #define MY_PATH <hello
    #define MY_FILENAME world
    #define MY_EXTENSION h>
    
    #include MY_PATH/MY_FILENAME.MY_EXTENSION

    I wasn't able to come up with anything to use the ## operator or to enclose the path in quotes instead of brackets...
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  4. #4

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Impossible? - #include and #define

    Solved

    sunburnt's <blah> idea works just fine if you make a minor modification to how gcc is called (by adding a -Ifoldername switch) and omitting the full path from the prefix.



    You've got to be a bit cunning with the naming convention of your header files though.
    I don't live here any more.

  5. #5
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: [RESOLVED] Impossible? - #include and #define

    Dear god.

    Thats one of the ugliest things I've seen!

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  6. #6

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: [RESOLVED] Impossible? - #include and #define

    Thanks I do try.

    Extremely useful though. Can't really say why because it's for work Trust me though this tangled web of macros is totally awesome.
    I don't live here any more.

  7. #7
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: [RESOLVED] Impossible? - #include and #define

    Haha. I'm sure its identical to why the PS2 header files are useful.. dear god those things are a mess.. but they get the job done

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width