What's the best way to do conditional compile?
-
I hate posting this, since probably 85% of general population actually love using #if and #ifdef and even see that's the only easy way to do "cross-platform". I don't, BTW. Here is my gripe. One #if is fine. Nested #if is nasty (I've seen #if else nested 8 level deep, with structures whose definition has more #if in it). Problem is #if begets another #if. I work in a company that has at least 90 conditional compile flags set into either makefile or command line. BTW, my Unix terminal has to scroll 4 pages for the complete build commands (and yes, mostly are the -D define flag). The worst part is the flags are peppered all over the code, maybe 2 millions LOC. And nobody bothers to consolidate them. I've seen a Linux distro that has parts of files that is different between platform stored in different directory. I couldn't remember what the Linux flavor was. They choose between target sources in makefile, instead of in the code. And the differences are stored in different dirs for ex. /x86 /alpha /risc, and these files have exactly same files with different content. I think this is a much more cleaner and maintainable approach. The key is to identify what would be different and consolidate it in one area. Any other ideas?
-
I hate posting this, since probably 85% of general population actually love using #if and #ifdef and even see that's the only easy way to do "cross-platform". I don't, BTW. Here is my gripe. One #if is fine. Nested #if is nasty (I've seen #if else nested 8 level deep, with structures whose definition has more #if in it). Problem is #if begets another #if. I work in a company that has at least 90 conditional compile flags set into either makefile or command line. BTW, my Unix terminal has to scroll 4 pages for the complete build commands (and yes, mostly are the -D define flag). The worst part is the flags are peppered all over the code, maybe 2 millions LOC. And nobody bothers to consolidate them. I've seen a Linux distro that has parts of files that is different between platform stored in different directory. I couldn't remember what the Linux flavor was. They choose between target sources in makefile, instead of in the code. And the differences are stored in different dirs for ex. /x86 /alpha /risc, and these files have exactly same files with different content. I think this is a much more cleaner and maintainable approach. The key is to identify what would be different and consolidate it in one area. Any other ideas?
crewchill wrote:
I've seen #if else nested 8 level deep, with structures whose definition has more #if in it
Well, that would certainly be a programming horror. Please, feel free to post it up so that we can all gasp in dismay and horror at the sheer beastly inhumanity of it.
Deja View - the feeling that you've seen this post before.
-
I hate posting this, since probably 85% of general population actually love using #if and #ifdef and even see that's the only easy way to do "cross-platform". I don't, BTW. Here is my gripe. One #if is fine. Nested #if is nasty (I've seen #if else nested 8 level deep, with structures whose definition has more #if in it). Problem is #if begets another #if. I work in a company that has at least 90 conditional compile flags set into either makefile or command line. BTW, my Unix terminal has to scroll 4 pages for the complete build commands (and yes, mostly are the -D define flag). The worst part is the flags are peppered all over the code, maybe 2 millions LOC. And nobody bothers to consolidate them. I've seen a Linux distro that has parts of files that is different between platform stored in different directory. I couldn't remember what the Linux flavor was. They choose between target sources in makefile, instead of in the code. And the differences are stored in different dirs for ex. /x86 /alpha /risc, and these files have exactly same files with different content. I think this is a much more cleaner and maintainable approach. The key is to identify what would be different and consolidate it in one area. Any other ideas?
Then you have for every platform own code, which will do the same. One change and you work in every file. I hate nested #if but this seems not to be better. X| I try to be prepared for this via structuring classes for use with or without API and MFC.:~
Greetings from Germany
-
I hate posting this, since probably 85% of general population actually love using #if and #ifdef and even see that's the only easy way to do "cross-platform". I don't, BTW. Here is my gripe. One #if is fine. Nested #if is nasty (I've seen #if else nested 8 level deep, with structures whose definition has more #if in it). Problem is #if begets another #if. I work in a company that has at least 90 conditional compile flags set into either makefile or command line. BTW, my Unix terminal has to scroll 4 pages for the complete build commands (and yes, mostly are the -D define flag). The worst part is the flags are peppered all over the code, maybe 2 millions LOC. And nobody bothers to consolidate them. I've seen a Linux distro that has parts of files that is different between platform stored in different directory. I couldn't remember what the Linux flavor was. They choose between target sources in makefile, instead of in the code. And the differences are stored in different dirs for ex. /x86 /alpha /risc, and these files have exactly same files with different content. I think this is a much more cleaner and maintainable approach. The key is to identify what would be different and consolidate it in one area. Any other ideas?
I Have put on hold certan project, i am using nested #if. I am using for a feature and permision to be build or not. I chose this aprouach, so it woudnt be hacked. Also an option to hardcode a connection string, or specificy manul. Another reason i have chosen is because i wanted to make open source, so if someone woud modify, then they coud get direct database accsess. But i have put it on hold, Because i am doing asp.net version, And when it will be finished, i woud have appropriate schema. The way it is currently progresing, i think i won't need nested #if statments, Instead if i woud put script betwen application and server.
-
I hate posting this, since probably 85% of general population actually love using #if and #ifdef and even see that's the only easy way to do "cross-platform". I don't, BTW. Here is my gripe. One #if is fine. Nested #if is nasty (I've seen #if else nested 8 level deep, with structures whose definition has more #if in it). Problem is #if begets another #if. I work in a company that has at least 90 conditional compile flags set into either makefile or command line. BTW, my Unix terminal has to scroll 4 pages for the complete build commands (and yes, mostly are the -D define flag). The worst part is the flags are peppered all over the code, maybe 2 millions LOC. And nobody bothers to consolidate them. I've seen a Linux distro that has parts of files that is different between platform stored in different directory. I couldn't remember what the Linux flavor was. They choose between target sources in makefile, instead of in the code. And the differences are stored in different dirs for ex. /x86 /alpha /risc, and these files have exactly same files with different content. I think this is a much more cleaner and maintainable approach. The key is to identify what would be different and consolidate it in one area. Any other ideas?
I maintain a thin client which was originally designed for Symbol Series 3000 DOS-based handheld computers. Over time it's been ported to desktop Windows (for testing), Palm (for Symbol's relatively short-lived Palm devices with integrated scanners), other DOS-based handhelds and a variety of Windows CE and Pocket PC-based devices. The device-specific stuff tended to be implemented originally with #ifdefs but where possible I've replaced that with separate implementations, where the code needed to be completely different. In some places, I've replaced platform defines with feature defines, and added a configuration header which sets the feature defines up appropriately per-platform (unfortunately Microsoft C 6.0 . Finally, to try to keep the number of builds manageable, in some places I've used dynamic loading on CE using LoadLibrary/GetProcAddress to detect whether a feature is supported. This can happen if you're trying to use some manufacturer-specific APIs, for example we try to determine whether a Symbol MC3000 has full waveform-audio support or simply a beeper. The waveform-audio version supports the beeper API but with a significant amount of latency, so we use our own waveform-generator where possible (and of course it's necessary on the non-Symbol devices anyway).
DoEvents
: Generating unexpected recursion since 1991 -
I hate posting this, since probably 85% of general population actually love using #if and #ifdef and even see that's the only easy way to do "cross-platform". I don't, BTW. Here is my gripe. One #if is fine. Nested #if is nasty (I've seen #if else nested 8 level deep, with structures whose definition has more #if in it). Problem is #if begets another #if. I work in a company that has at least 90 conditional compile flags set into either makefile or command line. BTW, my Unix terminal has to scroll 4 pages for the complete build commands (and yes, mostly are the -D define flag). The worst part is the flags are peppered all over the code, maybe 2 millions LOC. And nobody bothers to consolidate them. I've seen a Linux distro that has parts of files that is different between platform stored in different directory. I couldn't remember what the Linux flavor was. They choose between target sources in makefile, instead of in the code. And the differences are stored in different dirs for ex. /x86 /alpha /risc, and these files have exactly same files with different content. I think this is a much more cleaner and maintainable approach. The key is to identify what would be different and consolidate it in one area. Any other ideas?
can't you just replace a nested if with case statement in many cases?
-
can't you just replace a nested if with case statement in many cases?
-
I hate posting this, since probably 85% of general population actually love using #if and #ifdef and even see that's the only easy way to do "cross-platform". I don't, BTW. Here is my gripe. One #if is fine. Nested #if is nasty (I've seen #if else nested 8 level deep, with structures whose definition has more #if in it). Problem is #if begets another #if. I work in a company that has at least 90 conditional compile flags set into either makefile or command line. BTW, my Unix terminal has to scroll 4 pages for the complete build commands (and yes, mostly are the -D define flag). The worst part is the flags are peppered all over the code, maybe 2 millions LOC. And nobody bothers to consolidate them. I've seen a Linux distro that has parts of files that is different between platform stored in different directory. I couldn't remember what the Linux flavor was. They choose between target sources in makefile, instead of in the code. And the differences are stored in different dirs for ex. /x86 /alpha /risc, and these files have exactly same files with different content. I think this is a much more cleaner and maintainable approach. The key is to identify what would be different and consolidate it in one area. Any other ideas?
An example of a conditional compile would be:
// If you uncomment the following line I will beat you to death with a rusty, blunt instrument
// File.Delete("*.*");:)
-
I hate posting this, since probably 85% of general population actually love using #if and #ifdef and even see that's the only easy way to do "cross-platform". I don't, BTW. Here is my gripe. One #if is fine. Nested #if is nasty (I've seen #if else nested 8 level deep, with structures whose definition has more #if in it). Problem is #if begets another #if. I work in a company that has at least 90 conditional compile flags set into either makefile or command line. BTW, my Unix terminal has to scroll 4 pages for the complete build commands (and yes, mostly are the -D define flag). The worst part is the flags are peppered all over the code, maybe 2 millions LOC. And nobody bothers to consolidate them. I've seen a Linux distro that has parts of files that is different between platform stored in different directory. I couldn't remember what the Linux flavor was. They choose between target sources in makefile, instead of in the code. And the differences are stored in different dirs for ex. /x86 /alpha /risc, and these files have exactly same files with different content. I think this is a much more cleaner and maintainable approach. The key is to identify what would be different and consolidate it in one area. Any other ideas?
The use of good cross-platform libraries and API's helps reduce or prevent much preprocessor ugliness. If you do it like one person said, with a project/program for each platform, you can simplify that by encapsulating core functionality whenever possible for reuse with many platforms. I often do what I can to separate program logic from GUI code, so that I could port the software to many platforms, while leaving the main logic untouched. (Of course, wxWidgets or Qt with ANSI C++ often means I hardly change a thing, but most people aren't using such libraries...) -Nick P.