Can A C Console App Run On Linux And Windows Both
If I Make A Pr开发者_StackOverflow社区ogram In C Without Including Windows.h Header File Will It Run On Linux. I Am Making It In Code Blocks On Windows.
If you only use the Standard C Library you'll be fine. if you go including io.h
and conio.h
and other junk like that, then you won't be fine.
Obviously I am assuming you are not expecting a windows PE to run on linux (without WINE) or a linux ELF to run on windows (you have to recompile like @sehe suggests).
No, they use completely different executable formats. You will need to compile a separate executable for each platform. If you stick to standard C it should compile for either though.
Yes, it will unless you do some non-Linux specific (Windows or Mac) calls..which are unlikely, since you are not including <windows.h>
.
Technically speaking, it won't "run" on both Windows and Linux, but so long as you stick to the standard library, it'll compile on just about any platform.
精彩评论