ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have few source files (.c) working perfectly fine in gcc. Now i have to change the extension to cpp. When I did that it gave me a whole bunch of errors. any suggestions ??
I have few source files (.c) working perfectly fine in gcc. Now i have to change the extension to cpp. When I did that it gave me a whole bunch of errors. any suggestions ??
I do not quite understand what you want to do and why, anyway, C++ files (they might have .cpp extension) are compiled by 'g++'.
well .. i made a project using c language and used gcc compiler. Now i am being told that all those files should be a .cpp extension files. So i thought that just changing the file extension would do the trick but sadly its not. I tried using g++ and it gave me a pretty much the same errors...
well i was told to make it in c but for some compatibility reason i need the file extension to be cpp instead of c.
Maybe you misunderstood the instructions.
Maybe you are supposed to limit yourself to constructs that are valid in both C and C++. In that case, post the code and compile errors. Someone will probably tell you what aspect of the C code is invalid as C++.
If you are literally correct about those instructions (code in C but have the extension be cpp) then you can use the -x option in gcc as Wim Sturkenboom suggested.
Thank you guys, '-x c' is the thing I was looking for.
Just one last thing, can you tell me by doing so it would be following PURE c calling convention: like: when functions it would be passing all the parameters on the stack and will do NO name mangling like in c++
OS: Linux-32bit
Source files: C coding standard with cpp extension
I still think it is more likely you are misunderstanding the type of "compatibility" you are supposed to achieve and -x c is only what you think you were looking for, not what you should have been looking for.
But it's still nice to see this forum (Wim Sturkenboom in this case) can dredge up that kind of obscure answer so well. (I stopped reading Wim's post after his un helpful first line without seeing his helpful second line. I knew some such gcc option existed but no clue of details. So I skimmed through the man pages, found -x c, started to post that and only then noticed Wim already had.)
Quote:
can you tell me by doing so it would be following PURE c calling convention: like: when functions it would be passing all the parameters on the stack and will do NO name mangling like in c++
OS: Linux-32bit
Source files: C coding standard with cpp extension
The -x c will entirely treat your .cpp input files as .c files:
It will use pure c calling convention, including NO name mangling because it is processing the input as C, not in any way as C++.
It will pass calling parameters on the stack (as opposed to in registers or by other means) but that is because it is x86 architecture, not because it is C rather than C++.
On an architecture, such as x86_64, where C++ passes parameters in other ways (not all on the stack), C passes parameters the same as C++.
Yeah I do understand what I am trying to achieve is kinda weird but this is what the requirements demand. I was being told to code up the project using C language, C calling conventions (cdecl = __attribute__ ((cdecl))) but with .cpp extension.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.