Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


How do I know whether I am compiling C or C++? by Salem
Posted: 12 Jul 03

Most compilers can compile C programs and C++ programs, but for one reason or another, you need to be sure which language you're using.

Some reasons for doing this are:
1. Some features are interpreted differently between C and C++.  For example sizeof('a')
In C, this is the same as sizeof(int), in C++, its the same as sizeof(char).
A more complete list can be found here

2. You're a student studying C and you want to make sure that you don't learn any C++ by mistake.

Compilers normally use the file suffix to determine the language in use, so
For a C program, you save the file as prog.c
For a C++ program, you save the file as prog.cpp (or sometimes prog.cxx)

To make sure, compile this as a console program, and execute it to find out what it prints.
#include <stdio.h>

int main ( void ) {
#if defined(__cplusplus)
    printf( "Compiled with an ANSI-C++ compiler\n" );
#elif defined(__STDC__)
    printf( "Compiled with an ANSI-C compiler\n" );
    printf( "I don't know what standard your compiler is\n" );
    printf( "Press return\n" );
    return 0;

Back to C FAQ Index
Back to C Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close