Reputation: 9717
I am planning to write an ANSI-C program on Windows with Netbeans using Cygwin suite, and later on i want to compile the source code on an UNIX family OS and use the program. Should i worry about any kind of compability problems?
Upvotes: 0
Views: 352
Reputation: 62106
If you use only the functionality described in the C standard, the set of possible incompatibilities typically reduces to:
char
int
=long
=32-bit in Windows, not necessarily so on UNIX), I mean literally all, including pointers and enums
memcpy()
copies data (low to high addresses or the other way around), etc etci+i++
or a[i]=i++
, modifying string literals, pointer dereference when the object it's pointed to is gone (e.g. free()'d
), not using or misusing const
and volatile
, etc etcprintf()
-like functions with wrong number or kind of parametersThere's much more. You actually have to read the standard and note what's guaranteed to work and what's not and if there are any conditions.
If you use something outside of the C standard, that functionality may not be available or identical on a different platform.
So, yes, it's possible, but you have to be careful. It's usually the assumptions that you make that make your code poorly portable.
Upvotes: 1
Reputation: 1786
There will be comparability problems, but as long as you stick to basic unix functionality, they ought to be manageable for command line applications. However, if your app has a GUI or has to interact with other programs in the unix environment, you'll probably regret your approach.
Another way to go would be to run the appropriate flavor of unix in a virtualbox on your desktop, and be pretty sure there are no compatibility problems.
Upvotes: 1