[cfe-dev] Windows patches

Mike Stump mrs at apple.com
Thu Oct 8 18:46:33 PDT 2009


On Oct 8, 2009, at 5:42 PM, John Thompson wrote:
> Can you give me some pointers on how to do a platform-specific file?

Oh, there are lots of ways and llvm doesn't tend to have a beautiful  
way to do this...  but one way would be to arrange it like so:

#ifdef _MSC_VER
code
#endif

You can then just have it  built normally, and call the routines from  
the file from the other parts of the file.

So, for example, take a concepts called filename path canonicalization  
(just to pick a windows difference between unix).

Support/Paths.h:

   char *canonicalize(char *);

Support/UnixPaths.cpp:

   #ifndef _MSC_VER
   char *canonicalize(char *c) {
     while (c[0] == '/' && c[1] == '/') ++c;
     return c;
   }
   #endif

Support/WinPaths.cpp:

   #ifdef _MSC_VER
   char *canonicalize(char *c) {
     // ...
   }
   #endif

another approach would be llvm/lib/System/Atomic.cpp, though, I'm not  
sure I really like that style as much.  In general, one wraps up the  
system specific bits they want behind a system independent api, use  
that api in the main code, and then in the implementation, one can  
hide the details.



More information about the cfe-dev mailing list