Is C++ code different on mac and PC

In summary, the conversation discusses the issue of platform dependency in software development, specifically in terms of using C++ code on different operating systems such as Macs and PCs. The main points raised include the impact of libraries, vendor-specific compiler options, and differences in language implementation on the portability of code. It is noted that introductory C++ programming courses typically use text-based programs that can be easily transferred between operating systems, but there may be minor differences in setting up the terminal window. The conversation also touches on the use of <conio.h> and the potential issues with certain functions not working in newer versions of Visual Studio.
  • #1
rshalloo
52
0
I'm about to start a module in C++ programming and I was just wondering if the code I learn in college (on P.C's) will be useable on macs Xcode. As in will I be able to EXACTLY the same code on both?
 
Technology news on Phys.org
  • #2
Platform dependency is a big issue in all areas of software development.

Platform issues typically arise in three ways (listed in order of prevalence):

1) Libraries.

Windowing toolkits, networking, filesystems, even basic input and output depend on the underlying operating system for support. Since most operating systems do pretty much the same thing, this isn't a deal-killer. But every once in a while, you run into problems where some functionality is buggy or just plain undocumented.

2) Vendor-specific compiler options.

This is usually a bigger problem with compiled languages. Especially "standardized" compiled languages. While every vendor agrees on (most of) the spec for the language, they feel the need to add new features to lure in more users.

3) Allowances or ambiguities in the language spec, or failures in the language implementation.

Many languages are spec'ed. Common Lisp, C++, C, Scheme, Haskell, ML, and EcmaScript (Javascript) all have a written document that explains in fine detail how to write a compiler (or interpreter) for the language. The goal is to make all the implementations compatible. They rarely are. Either on the fault of the spec writer or the language implementor, differences in the implementations arise. Those differences become the responsibility of the developers to work around.
 
  • #3
I agree w/ Tic-Tacs post but would add that his point:

Windowing toolkits, networking, filesystems, even basic input and output depend on the underlying operating system for support. Since most operating systems do pretty much the same thing, this isn't a deal-killer. But every once in a while, you run into problems where some functionality is buggy or just plain undocumented.

is indeed not a deal-killer, BUT that simple statement glosses over the fundamental concept I would point out, which is that programming languages are not JUST languages. The syntax of the language will like have no more than small differences, but the differences in HOW the underlying operating systems do what they do can be quite different and the calls to OS functionality has to be learned independent of whatEVERY language is being used and in that sense, there are really significant differences.

SO ... if you write a = b + c, that will compile just fine under any implementation and any OS, but when you want to open a file or do something more complex by invoking the OS, then there is likely to be significant structural difference in the statements.

Thus, the fundamental LANGUAGE is no different at all, but PROGRAMMING with it can be quite different.
 
  • #4
The kind of stuff you do in an introductory C++ programming course is almost certain to be completely portable between MacOS, Windows and Linux. You don't do operating-system specific stuff (graphics, windows, etc.) in those courses. The programs will probably be purely text-based, and use the standard C++ input and output stream operations to read/write to a Windows or MacOS command-line terminal window, or to files.

Under Windows, you might have to use an extra #include directive at the beginning of a program in order to set up the terminal window, which you don't do under MacOS and Linux. If your program otherwise uses the standard C++ libraries, switching between operating systems should be simply a matter of adding or removing that #include.
 
  • #5
It has been my 2nd year using xcode for my C++ class. So far no major problems. However when you learn to open and read from .txt files, you will need to type in the exact location of where the file is at, rather than Windows compilers, where you would just type in the file name(since it expects the file to be in the same folder as the project). So far all good.
 
  • #6
jtbell said:
Under Windows, you might have to use an extra #include directive at the beginning of a program in order to set up the terminal window

nope

http://msdn.microsoft.com/en-us/library/fcc1zstk.aspx

"If main or wmain is defined for native code... CONSOLE is the default."

I doubt an include is required to have a console application with any other C++ complier/linker/environment for Windows.

Ivan92 said:
It has been my 2nd year using xcode for my C++ class. So far no major problems. However when you learn to open and read from .txt files, you will need to type in the exact location of where the file is at, rather than Windows compilers, where you would just type in the file name(since it expects the file to be in the same folder as the project). So far all good.

All the major PC operating systems support relative paths. You may have had a false idea of what the present working directory was.
 
Last edited:
  • #7
jtbell said:
Under Windows, you might have to use an extra #include directive at the beginning of a program in order to set up the terminal window

MisterX said:
nope

OK, so that's apparently changed since I used to hang out in the comp.lang.c++ Usenet newsgroup, several years ago. I remember seeing lots of people posting programs (that they were asking for help with) that had '#include <conio.h>' at the beginning.
 
  • #8
jtbell said:
I remember seeing lots of people posting programs (that they were asking for help with) that had '#include <conio.h>' at the beginning.
<conio.h> is used for functions like _cgets() and _cputs(). Note that Visual Studio (all versions or at least since VS 2005) broke _cgets(). I've read that using the unicode (16 bit wide character) option may fix this bug. I use Visual C 4.0 or 4.1 to compile old 32 bit programs that use these functions, or Visual C 2.2 to compile old 16 bit programs since _cgets() isn't broke in the older compilers.
 
Last edited:

1. Is C++ code compatible between Mac and PC?

Yes, C++ code is generally compatible between Mac and PC. However, there may be small differences in the libraries or compiler used, so some adjustments may need to be made for cross-platform compatibility.

2. Are there any differences in coding C++ on a Mac vs a PC?

The basic syntax and structure of C++ code is the same on both Mac and PC. However, there may be slight differences in the development environment and tools used, such as the text editor or compiler.

3. Can C++ programs written on a Mac be run on a PC?

In most cases, C++ programs written on a Mac can be compiled and run on a PC. However, as mentioned earlier, there may be small differences in the libraries or compiler used, so some adjustments may need to be made for cross-platform compatibility.

4. Are there any limitations to using C++ on a Mac or PC?

No, there are no specific limitations to using C++ on either a Mac or PC. However, the overall performance and capabilities of the program may depend on the hardware and operating system of the device it is running on.

5. Do I need to use different compilers for C++ on Mac and PC?

You can use the same compiler for C++ on both Mac and PC, such as the popular open-source compiler, GNU Compiler Collection (GCC). However, some developers may prefer to use different compilers for each platform for better optimization or compatibility.

Similar threads

  • Programming and Computer Science
Replies
1
Views
3K
Replies
3
Views
223
  • Programming and Computer Science
Replies
1
Views
887
  • Programming and Computer Science
Replies
7
Views
553
  • Computing and Technology
Replies
5
Views
1K
  • Programming and Computer Science
Replies
14
Views
2K
  • Programming and Computer Science
Replies
2
Views
169
  • Programming and Computer Science
Replies
8
Views
832
  • Programming and Computer Science
Replies
29
Views
2K
  • Programming and Computer Science
Replies
8
Views
2K
Back
Top