A compiler checks the syntax of source code from the text file. Why is it necessary to save it with an extension .c or .cpp?
I tried this on gcc but it does not compile a file with an extension other than .c and .cpp!!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The compiler won’t guess the language of the code in a file by looking at the text – you have to tell it what to compile as. Nearly every compiler allows this to be passed as a flag or it will infer it from the file extension. You’re quite free to compile a
.cppfile as pure C by passing the appropriate flag to your compiler so it needn’t infer it. However, this is a situation where following convention helps both you (less flags to pass around) and other programmers (who know the language from a quickls).