jamesadrian
Posts: 5
Joined: Sat Apr 16, 2016 10:27 pm
Location: Rochester, NY 14626
Contact: Website

C programming Language before C++

Sat Apr 16, 2016 10:32 pm

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

ejolson
Posts: 5189
Joined: Tue Mar 18, 2014 11:47 am

Re: C programming Language before C++

Sun Apr 17, 2016 6:22 pm

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.

rzusman
Posts: 347
Joined: Fri Jan 01, 2016 10:27 pm

Re: C programming Language before C++

Sun Apr 17, 2016 7:22 pm

What do you want, exactly?

User avatar
DougieLawson
Posts: 38863
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: C programming Language before C++

Sun Apr 17, 2016 8:14 pm

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?
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

jahboater
Posts: 5678
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: C programming Language before C++

Sun Apr 17, 2016 8:15 pm

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.
Pi4 8GB running PIOS64

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 26440
Joined: Sat Jul 30, 2011 7:41 pm

Re: C programming Language before C++

Sun Apr 17, 2016 8:16 pm

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.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

jahboater
Posts: 5678
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: C programming Language before C++

Sun Apr 17, 2016 8:24 pm

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.
Pi4 8GB running PIOS64

User avatar
buja
Posts: 563
Joined: Wed Dec 31, 2014 8:21 am
Location: Netherlands

Re: C programming Language before C++

Sun Apr 17, 2016 8:35 pm

The options to GCC enable certain aspects (language features and extensions), but you can always compile old style K&R C.

jahboater
Posts: 5678
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: C programming Language before C++

Sun Apr 17, 2016 8:54 pm

Code: Select all

sudo apt-get install gcc-4.9-doc
Then "man gcc" tells all.

I have a feeling the OP simply wants "C" instead of "C++".
Pi4 8GB running PIOS64

jamesadrian
Posts: 5
Joined: Sat Apr 16, 2016 10:27 pm
Location: Rochester, NY 14626
Contact: Website

Re: C programming Language before C++

Mon Apr 18, 2016 12:08 am

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

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: C programming Language before C++

Mon Apr 18, 2016 2:13 am

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!
marcus
:ugeek:

ejolson
Posts: 5189
Joined: Tue Mar 18, 2014 11:47 am

Re: C programming Language before C++

Mon Apr 18, 2016 5:46 am

MarkHaysHarris777 wrote:C++ has no structural constraints; none.
Just out of curiosity, what are structural constraints?

User avatar
PeterO
Posts: 5828
Joined: Sun Jul 22, 2012 4:14 pm

Re: C programming Language before C++

Mon Apr 18, 2016 7:54 am

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 :D
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

jamesadrian
Posts: 5
Joined: Sat Apr 16, 2016 10:27 pm
Location: Rochester, NY 14626
Contact: Website

Re: C programming Language before C++

Mon Apr 18, 2016 11:47 am

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

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 26440
Joined: Sat Jul 30, 2011 7:41 pm

Re: C programming Language before C++

Mon Apr 18, 2016 12:54 pm

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.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

scotty101
Posts: 3958
Joined: Fri Jun 08, 2012 6:03 pm

Re: C programming Language before C++

Mon Apr 18, 2016 3:26 pm

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.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

davenull
Posts: 1159
Joined: Thu Oct 22, 2015 7:22 am
Location: a small planet close to Betelgeuze

Re: C programming Language before C++

Mon Apr 18, 2016 6:47 pm

so if a code works by a ANSI C compiler , it also works by a C++ compiler
8-)

to say it mathematically, ANSI C is a subset of C++
:geek:

in kind of mathematical syntax:

Code: Select all

C++  = {x | x ∈ ANSI_C } ∪ {y | y ∈ c++_classes }  
so  
∀ x ∈ ANSI_C  ⇒  x ∈ C++ 

:ugeek:
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;int main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PointOut(x,y);}}}for(;;);}

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: C programming Language before C++

Mon Apr 18, 2016 8:15 pm

davenull wrote:so if a code works by a ANSI C compiler , it also works by a C++ compiler
8-)
to say it mathematically, ANSI C is a subset of C++
:geek:
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!! :lol:

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 !

:mrgreen:
marcus
:ugeek:

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: C programming Language before C++

Mon Apr 18, 2016 10:06 pm

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 :roll: 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...
marcus
:ugeek:

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: C programming Language before C++

Mon Apr 18, 2016 11:55 pm

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:

Code: Select all

sudo apt-get install clang
This will also install LLVM 3.5 and you'll be set. Call it the same way you would call gcc:

Code: Select all

clang -Wall -o helloworld hello.c
Try this for an interesting display:

Code: Select all

clang -v
Also, look here for clang:

Code: Select all

/usr/lib/llvm-3.5/bin/
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.
marcus
:ugeek:

Return to “C/C++”