does the file extension matter how it's compiled?

S

smnoff

I have a file, say test.c and I want to compile is and I happen to look and
it appears to be compiled like a C++ file.
So does it matter is the file extension where to written as test.cpp
 
G

Guest

smnoff said:
I have a file, say test.c and I want to compile is and I happen to look and
it appears to be compiled like a C++ file.
So does it matter is the file extension where to written as test.cpp

This depends on the compiler, but since it is compiled as C++ code even
with a .c file extension -- your message is not very clear, but this is
what you appear to be saying -- apparently the file extension does not
matter for yours.
 
R

Randy Howard

I have a file, say test.c and I want to compile is and I happen to look and
it appears to be compiled like a C++ file.
So does it matter is the file extension where to written as test.cpp

I'm not sure I understand your question, but my guess is you want to
know if source code will be compiled differently based upon the
filename being changed from test.c -> test.cpp (or vice versa).

Several compilers I've used on various platforms will change their
compilation behavior based upon that. Source files with a .cpp
"extension" in those environments will compile as if the code is C++,
even if that is not your original intent.

IIRC there is nothing in the C standard that describes that behavior.
 
J

jacob navia

smnoff a écrit :
I have a file, say test.c and I want to compile is and I happen to look and
it appears to be compiled like a C++ file.
So does it matter is the file extension where to written as test.cpp
It depends on the compiler, as people have already said.
Many compilers have an option that allow to force the
type of language they will compile, when they are
multi-language compilers.

Other compilers compile just one language, so they ignore
the suffix of the source code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top