C++ differences between linux and windows
by Weston Howard · in Technical Issues · 11/11/2004 (5:37 am) · 5 replies
Hey, I'm new at programming, so I thought mayby I'd ask for a little advice.
I've been learning C++ on my windows machine, but now that I've switched to linux (redhat 9) I noticed the C++ commands are slightly different. (eg. "endl;" and ";" commands) can you switch a compiled program from windows to linux or vise versa? Or do you have to edit them?
I've been learning C++ on my windows machine, but now that I've switched to linux (redhat 9) I noticed the C++ commands are slightly different. (eg. "endl;" and ";" commands) can you switch a compiled program from windows to linux or vise versa? Or do you have to edit them?
#2
11/11/2004 (6:15 pm)
Yes, it has nothing to do with these operating systems. C++ is just a language, a white paper sitting on someone's desk. Its implementation may differ depending on whom you talk to. [These are the people writing the compilers and runtime libraries you use in programming.] What differences have you come across?
#3
11/14/2004 (12:05 pm)
Most of the differences are the way you end lines, also, it seems my compiler is realy touchy about commands. For instance I was reading from a C++ help book about the int main (void) headings at the start of my files. My compiler doesn't like (void) or several other inputs, only seems to like (int) or some odd one called (arcg). I often have trouble entering examples strait from several books (eg. C++ demistified, or opengl programing basics), Is this due to libraries that only exist on certain compilers or operating systems?
#4
11/15/2004 (12:20 am)
Quote:Most of the differences are the way you end linesendl is the correct way to end a line when using cout. It's converted to '\r\n' under Windows, '\n' under Unix/Linux and '\r' on the Mac as these are what the respective OSes expect the newline character to be. If you've been using '\n' then that's not guaranteed to have the desired result on all platforms (especially the Mac).
Quote:For instance I was reading from a C++ help book about the int main (void) headings at the start of my filesint main(void) is incorrect C++. It should really be int main() or int main(int argc, char **argv) (argc is the number of command line parameters, argv is an array (size argc) of pointers to char strings containing the commands).
Quote:I often have trouble entering examples strait from several books (eg. C++ demistified, or opengl programing basics), Is this due to libraries that only exist on certain compilers or operating systems?Possibly, or it might be sloppy code in the book. gcc likes the code to adhere to C++ standards, VC++ doesn't care so much. You'll need the OpenGL dev libraries and headers installed if you haven't already. Also, there's no Win32 API or MFC under Linux (thank goodness) and you'll have to use something like wxWindows or GTK+ instead. If you want DirectX bits you might want to look at SDL.
#5
11/16/2004 (6:29 pm)
Hey thanks, that cleared up some of the problems I was having in my program. I must have gone over those command lines for hours before giving up. Mined if I ask, how long have you guys been working with programing? And, any tips for the new guy on the block? Is there a good help book that I should pick up? Specificaly books that discuss C++ in a linux setting, or with generic compilers, instead of specific windows compilers.
William Finlayson
It should be easy to port them if you have been using only cross-platform libraries, otherwise you will run in to problems, and need to alter your source. C++ itself should be the same an both platforms, but that depends on what standards you/your compiler use.