0

I have a question. Supose that 2 teams makes modification on a source file that include a header "test.c" But one had that file called "test.C" and the another one had it called "test.c" Is there a way to conditional include that file in C? Something like:

#ifdef test.C
    #include "test.C"
#else
    #include "test.c"
#endif
4
  • 1
    Why don't you try that and see if it works? Also, this is what source control is for, not conditional includes. Make a branch (using git, it's quite easy), and have people make changes in different branches.
    – xaxxon
    May 19, 2013 at 8:50
  • 2
    That sounds like a bad naming convention. I don't understand why you want it in this particular case (although there are reasons to want it), but the c preprocessor has no method to check if files exist. You could use a makefile or similar to define certain constants.
    – Dave
    May 19, 2013 at 8:51
  • I think its time you should use some kind of version control like SVN May 19, 2013 at 8:51
  • ok, thanks a lot! I hoped that is a way to check what file exist. Yes, is a bad naming convention, but I have a project and I don't know with wich name my teacher will test the program and that's why I asked.
    – 23ars
    May 19, 2013 at 8:55

1 Answer 1

0

As Dave correctly stated, the c preprocessor has no method to check if files exist. But provided with a suitable shell and a compiler which allows to define a macro on the command line, you can do something like

set test.?; cc source.c -DTEST=\"$1\"

and in the source file have

#include TEST

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.