user6595053 user6595053 - 1 year ago 75
C Question

Cygwin: Linux on Windows? How to ensure that program created in Windows works for Linux

we have a school project and it requires our C programs to work on Linux and is c99 compatible. Since I am working on Windows 10, I installed Cygwin and assumed that if it will compile in cygwin, it will most certainly work in Linux. It works fine with windows and I tried to compile it in cygwin and it works as well. So can I assure that it will work in Linux and is C99 Compatible? If no, why not? I am only using stdio and stdlib

Answer Source

You can never be sure. Even though your program seems to work it may still contain bugs that invoke undefined behaviour.

However, you can reduce the risk of malfunctions by using best practice, for example:

Heed compiler warnings

Turn up compiler warning. For example:

gcc -Wall -pedantic -std=c99

This turns up the warning level to a fairly high level. . Compiler warnings are often indications of bugs, so fix them all.

-std=c99 tells the compiler to use the rules for the C99 version of the C standard

Use Valgrind to detect invalid use of memory

Valgrind will report common memory bugs like buffer overruns and memory leaks.