C - How do you ignore certain code depending on the OS (so one source code to fit all) -
i want make source of program cross-platform, , far good. have couple of functions differ in syntax, checking defines @ start see if windows or linux , setting variable 1 or 0 depending on 1 is. thinking if statement check on variable skip incorrect syntax usage. have realised won't compile because compiler still 'sees' offending code. can you
#ifdef
to compartmentalize functions , call them within code? suggestions?
you have enclose entire non cross-platform section between #ifdef
s.
for instance:
int gettimeofday(struct timeval *tp, void *tzp) { #ifdef win32 struct _timeb timebuffer; _ftime(&timebuffer); tp->tv_sec = timebuffer.time; tp->tv_usec = timebuffer.millitm * 1000; return 0; #else tp->tv_sec = time(null); tp->tv_usec = 0; return 0; #endif }
like compiler won't see offending code since removed @ preprocessing step.
Comments
Post a Comment