Page 1 of 1
C programming Language before C++
Posted: Sat Apr 16, 2016 10:32 pm
by jamesadrian
Is there C a compiler that works they way it did before C++ ? I would like to won one for use on OS X.
Thank you for your help.
Jim Adrian
Re: C programming Language before C++
Posted: Sun Apr 17, 2016 6:22 pm
by ejolson
jamesadrian wrote:Is there C a compiler that works they way it did before C++ ? I would like to won one for use on OS X.
Thank you for your help.
Jim Adrian
As far as I can tell there are no actively maintained C compilers that support the original K&R definition of C. You may be able to run an old K&R C compiler under some sort of emulator as in the
computer history simulation project. On the other hand ANSI C, though influenced by C++, was designed to be forward compatible with most K&R style C code. If you are leaning C for the first time and not interested is reliving the historical evolution of the C programming language, I would suggest starting with the C99 standard of the language which includes complex numbers and variable length arrays. Note that neither of these C99 language features resemble anything in C++ and instead represent a separate evolution of the original C language. Any recent version of gcc with the option -std=gnu99 can be used to compile C99 compliant C code.
Re: C programming Language before C++
Posted: Sun Apr 17, 2016 7:22 pm
by rzusman
What do you want, exactly?
Re: C programming Language before C++
Posted: Sun Apr 17, 2016 8:14 pm
by DougieLawson
jamesadrian wrote:Is there C a compiler that works they way it did before C++ ? I would like to won one for use on OS X.
What is it about
cc or
gcc that doesn't work for you?
Re: C programming Language before C++
Posted: Sun Apr 17, 2016 8:15 pm
by jahboater
Do you mean C (instead of C++) or do you mean an early version of C?
If you could say why, it might help too.
Re: C programming Language before C++
Posted: Sun Apr 17, 2016 8:16 pm
by jamesh
Can you specify to gcc that you want a specific version of C to be used? I thought that was possible. Whether you can make it go back that far I don't know.
Re: C programming Language before C++
Posted: Sun Apr 17, 2016 8:24 pm
by jahboater
jamesh wrote:Can you specify to gcc that you want a specific version of C to be used? I thought that was possible. Whether you can make it go back that far I don't know.
You can go back as far as C89 (iso9899:1990) which is later than K&R. (-std=c89). There is also -std=c99 and the default which is -std=c11, the latest standard. Changing c11 to gnu11 allows all the (useful) gnu extensions.
Re: C programming Language before C++
Posted: Sun Apr 17, 2016 8:35 pm
by buja
The options to GCC enable certain aspects (language features and extensions), but you can always compile old style K&R C.
Re: C programming Language before C++
Posted: Sun Apr 17, 2016 8:54 pm
by jahboater
Then "man gcc" tells all.
I have a feeling the OP simply wants "C" instead of "C++".
Re: C programming Language before C++
Posted: Mon Apr 18, 2016 12:08 am
by jamesadrian
I looks like I should learn more about gcc with the option -std=gnu99.
I am concerned about the structural constraints imposes by C++
Thank you all for your comments.
Jim Adrian
Re: C programming Language before C++
Posted: Mon Apr 18, 2016 2:13 am
by MarkHaysHarris777
jamesadrian wrote:
I am concerned about the structural constraints imposes by C++
I am sorry, but that is rediculous.
There are only four reasons to use C++ over C...
1) You want to use the iostream library (and yes, that is reason enough).
2) You want to use polymorphism (virtual function tables)
3) You want to build Classes and use inheritance... and four
4) You want to use some third party library only written in C++
C++ has no structural constraints; none. Having said that, some new users of the compiler are confused, for instance, that some C++ library functions take only a const reference to void... and they say, what the hell? (and other examples like that... but those are NOT structural constraints.
Having said all of that, if you're not using the iostream library, nor needing virtual function tables, nor needing Classes with inheritance, nor needing a C++ third party libary for some reason (some version of GPIO control) then just use C... and by the way... don't worry about what level... just use gcc the way it came to you and compile until you have removed all of the warnings!
Re: C programming Language before C++
Posted: Mon Apr 18, 2016 5:46 am
by ejolson
MarkHaysHarris777 wrote:C++ has no structural constraints; none.
Just out of curiosity, what are structural constraints?
Re: C programming Language before C++
Posted: Mon Apr 18, 2016 7:54 am
by PeterO
ejolson wrote:MarkHaysHarris777 wrote:C++ has no structural constraints; none.
Just out of curiosity, what are structural constraints?
Google doesn't seem to know what they are either
PeterO
Re: C programming Language before C++
Posted: Mon Apr 18, 2016 11:47 am
by jamesadrian
Marcus,
I don't want to build classes and use inheritance and I didn't understand the degree to which it might be an obligation in C++ . Thank you for your very informative answer.
Jim Adrian
Re: C programming Language before C++
Posted: Mon Apr 18, 2016 12:54 pm
by jamesh
jamesadrian wrote:Marcus,
I don't want to build classes and use inheritance and I didn't understand the degree to which it might be an obligation in C++ . Thank you for your very informative answer.
Jim Adrian
You really don't need to use classes in C++, which means you can use all the other benefits, and they are very useful benefits, some of which are outlined above, to which I would add function templates, and some of the other std:: libraries like vector, map etc which means you no longer have to write lots of boilerplate code. Note they are classes, but they are very optimal, and you don't need to use you own classes to use library classes.
Re: C programming Language before C++
Posted: Mon Apr 18, 2016 3:26 pm
by scotty101
Agreed. Use of classes is entirely optional in C++.
C++ was the first language taught on my University course but we just used it for functions and the iostream library. It wasn't until we did Object Oriented programming in the second year that we started to use classes.
Re: C programming Language before C++
Posted: Mon Apr 18, 2016 6:47 pm
by davenull
so if a code works by a ANSI C compiler , it also works by a C++ compiler
to say it mathematically, ANSI C is a subset of C++
in kind of mathematical syntax:
Code: Select all
C++ = {x | x ∈ ANSI_C } ∪ {y | y ∈ c++_classes }
so
∀ x ∈ ANSI_C ⇒ x ∈ C++

Re: C programming Language before C++
Posted: Mon Apr 18, 2016 8:15 pm
by MarkHaysHarris777
davenull wrote:so if a code works by a ANSI C compiler , it also works by a C++ compiler
to say it mathematically, ANSI C is a subset of C++
This answer is slightly oversimplified, but yes... C is a subset of C++ ...often, as is the case for gcc, the compiler is the same one (for all intents and purposes).
gcc is a subset of g++
Another way to think about C++ is that it is C with a better concept of struct. A C++ Class takes the struct concept and expands upon it. We can make 'new types' with the struct, in C. We can make 'new types & give them methods' with the Class in C++.
When I worked at the lab @ Rochester we had a massive rethreading (retraining) go on internally; because we decided to write the AS/400 operating system in C++ ( and many of the developers were not as yet C++ trained ). Winona State University and a company called "Paradigm Shift" were brought in-house to train C programers C++/ it was fabulously fun, and in some ways comical. The probelm with C++ is that its not about a new language syntax (the syntax is really just C) its about a new philosophy regarding how we think about programming in general (objects vs procedural). True story-- many of the guys and gals thought they had to place their code (their main) in a Class! It was really quite comical... otherwise, they didn't do anything else with the super-set called C++/ but they had Class!!
This gets further confused for newbies to C++, especially if they know something about Java; because Java DOES require that you put your main() in a Class! Ha! (did I say that Java sucks, already?)
PS I agree with Jamesh's comment, and I will add... almost forgot... function overloading !

Re: C programming Language before C++
Posted: Mon Apr 18, 2016 10:06 pm
by MarkHaysHarris777
The problem with learning C++ is that much of the philosophical concept behind it is very difficult to grasp without the sophistication required to know why its even necessary or beneficial. Also, its hard to teach C++ (or write a tutorial for it) because much of what C++ ( IS ) requires all of it to be there..!! It is literally one of those sets of concepts that is hard to get to from here...
... honestly, the best way to pick up C++ is from a college or university (audit a good course on object oriented progamming which features C++ as the primary method).
Another is to study all the code you can get your hands on... and READ everything out there... most of the books (good ones listed below) are huge, and are NOT a lite read (just a warning, not meant to be a discouragement).
This is my book-list linked by author/
Strustroup
Trivedi
Josuttis
Swan
Liberty - Horvath
Cline - Lomow - Girou
Of course, Stroustrup above

invented C++... Cline, Lomow, & Girou are the guys who came to IBM in the early '90s to teach from 'Paragidm Shift', ... Swan's book is probably my favorite (if there is one favorite). If you can only purchase ONE book get the 21days book - from Liberty & Horvath !
Best of luck...
Re: C programming Language before C++
Posted: Mon Apr 18, 2016 11:55 pm
by MarkHaysHarris777
jamesadrian wrote:Is there [a C] compiler that works they way it did before C++ ? I would like to [own] one for use on OS X.
Getting back to your original question...
... the newer
clang is an
LLVM front-end that is gaining popularity on OSX and in other places where high-end maths are required (modern FORTRAN) and other places.
To get clang for the RPi use:
This will also install LLVM 3.5 and you'll be set. Call it the same way you would call gcc:
Try this for an interesting display:
Also, look here for clang:
edit: You'll notice clang++ is a symbolic link to clang!
edit: Also, OSX has for some time used gcc by default; but now (and I think since the thrust of Swift) mac developers are using Swift and the LLVM-7.3.0 compiler with the clang front-end. In fact, on my El Capitan iMac I'm noticing that gcc is actually linked to clang (clang-703.0.29) and the LLVM-7.3.0 compiler.