|
-
Sep 5th, 2007, 06:39 AM
#1
[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.
-
Sep 5th, 2007, 08:52 AM
#2
Addicted Member
Re: Impossible? - #include and #define
Dude...I think that's impossible
-
Sep 5th, 2007, 02:29 PM
#3
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.
-
Sep 6th, 2007, 06:12 AM
#4
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.
-
Sep 6th, 2007, 06:13 AM
#5
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
-
Sep 6th, 2007, 06:19 AM
#6
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.
-
Sep 6th, 2007, 06:25 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|