[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.
Re: Impossible? - #include and #define
Dude...I think that's impossible
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...
Re: Impossible? - #include and #define
Solved :D
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. :D
Re: [RESOLVED] Impossible? - #include and #define
Dear god.
Thats one of the ugliest things I've seen! :p
chem
Re: [RESOLVED] Impossible? - #include and #define
Thanks :D 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.
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 :p
chem