
-----------------------------------
DtY
Sat Aug 22, 2009 10:24 pm

concatenating Directories
-----------------------------------
If you have the directory 'a' with the file 'b' in it, it would be 'a/b' on Unix, but 'a\b' on Windows. In Pyhton, this could be solved by using os.path.join('a', 'b'), and this is what I came up for in C:
#define PATH_JOIN(a,b) "a/b" /* Unix */
#define PATH_JOIN(a,b) "a\\b" /* Windows */
This works for what I currently need it for, however it has the downside that it only works with two constants. You can't use user input in any way, or any other variables.

I also tried
#define SLASH /
"aSLASHb"
However, the compiler (at least GCC) doesn't expand macros inside strings, which makes sense.

Is there a better way to join directories?

-----------------------------------
rdrake
Sat Aug 22, 2009 11:11 pm

RE:concatenating Directories
-----------------------------------
People on the internets say in C you can just use a forward slash for everything and it's supposed to work properly on every platform.

Are you just trying to open a file or are you doing something else?

Source:  [url=http://www.codeguru.com/forum/showthread.php?t=179376]here.

-----------------------------------
DtY
Sun Aug 23, 2009 11:20 am

RE:concatenating Directories
-----------------------------------
Thank you. That looks like what I need :D
I'll be using fopen(), and SDL_loadBMP(), which I assume uses fopen()

-----------------------------------
OneOffDriveByPoster
Sun Aug 23, 2009 5:16 pm

Re: concatenating Directories
-----------------------------------
#define PATH_JOIN(a,b) "a/b" /* Unix */
#define PATH_JOIN(a,b) "a\\b" /* Windows */...
However, the compiler (at least GCC) doesn't expand macros inside strings, which makes sense.

It does not make sense for it to replace supposed macro parameters inside a string either.

-----------------------------------
btiffin
Sun Aug 23, 2009 10:52 pm

Re: concatenating Directories
-----------------------------------
In the Just in case you ever need to know department
http://en.wikipedia.org/wiki/C_preprocessor#Quoting_macro_arguments

The #var trick can be used with auto literal concat in C to let you build up literals in code with the preprocessor

Something like
Untested, and cpp can pass on data dependent quoting weirdness And, it'll be far better to follow previous advice and not mucky muck with platform path issues unless you really really have to.

Cheers
