VOGONS


Ansi C or C++?

Topic actions

First post, by Zirias

User metadata
Rank Newbie
Rank
Newbie

Hi,
I just wanted to do some little modifications and was quite surprised to find only plain old C code in the .cpp files. Is there a particular reason for using a C++ compiler (along with libstdc++ et al)?

edit: I just discovered openglide INDEED compiles fine using gcc (and NOT g++), so there's definitely no c++ code anywhere. This helps me build a i386 version on my amd64 host right now, because my debian environment doesn't provide ia32 libstdc++ import library ATM.

So, why is all the code in .cpp files? Is this for building in microsoft visual studio, that doesn't provide a plain C compiler but only C++? If so, wouldn't setting CXX="gcc" on any GNU environment by default be a good idea?

Reply 1 of 5, by MattRocks

User metadata
Rank Oldbie
Rank
Oldbie

Anecdotal evidence only, but when I worked with C and C++ in large organisations the developers did strange things because they were more constrained by policies and working conditions.

Some employers had offline development environments, banned stack exchange, and decisions were made in closed rooms with small scrum teams operating to aggressive time frames.

It would be common to hear disputes over which compiler was better for debugging, produced more optimised code, etc. The decision would be made in the ceremony under vote if necessary.

Similar things happened in more public projects too. I remember being banned from one forum because my opening post was on translating some PHP into Perl.

I later discovered their lead engineer had left the organisation and launch a rival PHP version of an existing Perl product, the old injured organisation was tense, and I asked the wrong question at the wrong time.

So it’s quite believable that OpenGlide adopted C on g++ to pamper a momentary ego that nobody wants to talk about.

Hope that helps? 😀

Desktop timeline [ MOS 7501 → 68030 → x86(P5/MMX) → x86(K6-2) → x86(K7*) → PPC(G3*) → x86-64(K8) → x86-64(Xeon) → x86-64(i5) → x86-64(i7) ] * lost

Reply 2 of 5, by jmarsh

User metadata
Rank Oldbie
Rank
Oldbie

OP hasn't been active since 2017 and posted this question 7 years before that. I doubt they've been waiting for someone to guess an answer.

Reply 3 of 5, by Errius

User metadata
Rank l33t
Rank
l33t

C is valid C++ so why wouldn't you use a C++ compiler

"This all reminds me when i took the windows vista sticker thingy off my old laptop, and on my washing machine as a joke. A few days later said washing machine stopped working. I still think this cannot be a coincidence."

Reply 4 of 5, by MagefromAntares

User metadata
Rank Newbie
Rank
Newbie
Errius wrote on Today, 07:45:

C is valid C++ so why wouldn't you use a C++ compiler

While this is mostly true, yes most C is valid C++, but there are slight differences, for example C lets you convert void pointers to other kind of pointers without explicit conversion:

Valid C but invalid C++ code:

char* somedata = malloc(size);

This will fail on C++ compilers because they don't convert void pointers automatically to other types, and some kind of cast needs to be used to convert the result.

Reply 5 of 5, by wbahnassi

User metadata
Rank Oldbie
Rank
Oldbie

Pure C code in .cpp extension is not right, and there are no reasons related to Visual Studio that push people to such confusing file naming. The Microsoft compiler can be forced to compile C and error out on C++ regardless of file extension, but IIRC it does that automatically with files of .c extension.. so just name the files properly to first let people know which language to use, and second have the toolchain do the right thing.

Now the choice of whether to allow some C++ in C is something else that is really up to the taste of the project owner. Each have their way...

Turbo XT 12MHz, 8-bit VGA, Dual 360K drives
Intel 386 DX-33, Speedstar 24X, SB 1.5, 1x CD
Intel 486 DX2-66, CL5428 VLB, SBPro 2, 2x CD
Intel Pentium 90, Matrox Millenium 2, SB16, 4x CD
HP Z400, Xeon 3.46GHz, YMF-744, Voodoo3, RTX2080Ti