C programming file extensions

hey

I want to ask whether compiler or language itself describes its file extension. e.g for c programming we use .c file extention who describes them ? This question arose when gcc compiler and Microsoft visual C 6.0 compiler behaved differently for the file extension. Take a look at this simple C Code:

[code]

#include
int main(void){
printf("hello");
return 0;
}

[/code]

Save this file as .c and compile with gcc compiler (gcc -Wall file.c) and you will get expected output but saving the same file with .cpp extension and compiling with gcc compiler gave errors.

Now coming to Micosoft visual c++ even if you compile the code with .cpp extension (Although it is pure C code) it doesnot mind?

why??
plz someone reply
thanks

Comments

  • Compilers use the file extension to determine if it is a C file or C++ file (*.c or *.cpp). While C is a valid subset of C++, some compilers will complain unless you use the __cplusplus - extern "C" - macro.

  • : Compilers use the file extension to determine if it is a C file or C++ file (*.c or *.cpp). While C is a valid subset of C++, some compilers will complain unless you use the __cplusplus - extern "C" - macro.
    :


    I think gcc might moan about using obsolete headers if you use rather than when compiling as C++.
  • :
    : Save this file as .c and compile with gcc compiler (gcc -Wall file.c) and you will get expected output but saving the same file with .cpp extension and compiling with gcc compiler gave errors.
    :

    gcc is a c compiler, not a c++ compiler. If you want to compile c++ code use g++, not gcc. Also g++ expects .cc extension, not .cpp, but I suppose there are options to change that.
  • thanks everyone :)


    : : Compilers use the file extension to determine if it is a C file or C++ file (*.c or *.cpp). While C is a valid subset of C++, some compilers will complain unless you use the __cplusplus - extern "C" - macro.
    : :
    :
    :
    : I think gcc might moan about using obsolete headers if you use rather than when compiling as C++.
    :

  • : :
    : : Save this file as .c and compile with gcc compiler (gcc -Wall file.c) and you will get expected output but saving the same file with .cpp extension and compiling with gcc compiler gave errors.
    : :
    :
    : gcc is a c compiler, not a c++ compiler. If you want to compile c++ code use g++, not gcc. Also g++ expects .cc extension, not .cpp, but I suppose there are options to change that.
    :

    once upon a time gcc was a c compiler and stood for gnu c compiler however nowadays it is a collection of compilers and stands for gnu compiler collection. Meaning generally gcc is a c++ compiler. But I've used it to compile Java, FORTRAN and C++.
  • : : :
    : : : Save this file as .c and compile with gcc compiler (gcc -Wall file.c) and you will get expected output but saving the same file with .cpp extension and compiling with gcc compiler gave errors.
    : : :
    : :
    : : gcc is a c compiler, not a c++ compiler. If you want to compile c++ code use g++, not gcc. Also g++ expects .cc extension, not .cpp, but I suppose there are options to change that.
    : :
    :
    : once upon a time gcc was a c compiler and stood for gnu c compiler however nowadays it is a collection of compilers and stands for gnu compiler collection. Meaning generally gcc is a c++ compiler. But I've used it to compile Java, FORTRAN and C++.
    :


    The other executables of the collection are still there. When you call 'gcc', it calls for you the appropriate compiler (whether it be g++, g77...)

    {2}rIng
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories