Stupid question.

Electronics Computer Programming Q&A
Post Reply
EEPROM777I
Posts: 29
Joined: Tue Jul 18, 2006 8:48 pm
Contact:

Stupid question.

Post by EEPROM777I »

This is idiotic but it occurred to me the other day. C++ is an updated version of C right? So it's C incremented (C=C+1 // C++) to the next version? Is that where C++ came from or does it have some other significance?
KamPutty
Posts: 67
Joined: Sun Feb 19, 2006 1:01 am
Contact:

Post by KamPutty »

My understanding is that "C++" does mean what you said, the next C increment.

Would ++C be different then C++?! :lol: :lol: :lol: :lol:

~Kam (^8*
ku7485
Posts: 103
Joined: Thu Jul 06, 2006 1:26 pm
Location: California, USA
Contact:

Post by ku7485 »

Your question got me thinking about it also EEPROM7771. :grin: Looked it up in Wikipedia and I guess your assumption was correct: http://en.wikipedia.org/wiki/C++#The_name_.22C.2B.2B.22
jlarson43
Posts: 9
Joined: Sat Apr 08, 2006 3:28 pm
Location: Dayton, Ohio
Contact:

Post by jlarson43 »

KamPutty wrote:My understanding is that "C++" does mean what you said, the next C increment.

Would ++C be different then C++?! :lol: :lol: :lol: :lol:

~Kam (^8*
It depends on the context.

When C++ occurrs in an expression, the value of C is used and then the variable is incremented by one.

When ++C occurs in an expression, C is incremented first and then the new value is used.

In Case 1, C will be incremented by 1 and then compared to MAX_VAL.

/* Case 1 */
if (++C > MAX_VAL)
/* condition true */ ;
else
/* condition false */
/* End Case 1 */

In Case 2, C will be compared to MAX_VAL unchanged, a note taken, and then C is incremented by 1.

/* Case 2 */
if (C++ > MAX_VAL)
/* condition true */ ;
else
/* condition false */
/* End Case 2 */


Case 1 can be coded as:

/* Alternative Case 1 */
C = C + 1;
if (C > MAX_VAL)
/* condition true */ ;
else
/* condition false */
/* End Alternative Case 1 */

Case 2 is equivalent to:

/* Alternative Case 2 */
bool CondFlag = C > MAX_VAL;
C = C + 1;
if (CondFlag)
/* condition true */ ;
else
/* condition false */;
/* End Alternative Case 2 */

All by its lonesome, C++; is equal to ++C;

See page 42, Section 2.8 of Kernighan & Ritchie's classic book, "The C Programming Language" Prentice-Hall, Inc., (c) 1978.

Hope this helps.
James Larson
Programmer/Analyst Consultant
http://www.dst-corp.com/james
In God We Trust...
User avatar
philba
Posts: 2050
Joined: Tue Nov 30, 2004 1:01 am
Location: Seattle
Contact:

Post by philba »

funny, the C language was derived from a language called B which was derived from a language called BCPL. So maybe C++ should have been called P.
User avatar
MrAl
Posts: 3862
Joined: Fri Jan 11, 2002 1:01 am
Location: NewJersey
Contact:

Post by MrAl »

Hi,

Interesting, sometimes it's written as CPP or cpp. Many of
the files use the suffix cpp instead of c as in "filename.cpp".
LEDs vs Bulbs, LEDs are winning.
jlarson43
Posts: 9
Joined: Sat Apr 08, 2006 3:28 pm
Location: Dayton, Ohio
Contact:

What's in a name?

Post by jlarson43 »

philba wrote:funny, the C language was derived from a language called B which was derived from a language called BCPL. So maybe C++ should have been called P.
Personally, I think <b>C++</b> is a very appropriate name. I intuitively associate <b>P</b> with <b>Pascal</b>, not C. When I see C++, I recognize the purpose of the ++ operator, and instantly know that C++ is based on C. Ironically, the reason I ran out and bought <b>Borland's C/C++ V1.0</b> system was because I wanted a C IDE. But it wasn't until I had advanced to <b>Microsoft Visual C/C++ V5.0</b> that I discovered the richness and shear power of C++.

I'm glad I learned C before C++. There are many things I prefer to do the old C way rather than the C++ way, like <i>printf</i> instead of the <i>overloaded <<</i> operator for output. Because of my C background, I am free to choose the approach that I like best, and the compiler doesn't care.
James Larson
Programmer/Analyst Consultant
http://www.dst-corp.com/james
In God We Trust...
User avatar
philba
Posts: 2050
Joined: Tue Nov 30, 2004 1:01 am
Location: Seattle
Contact:

Post by philba »

I thought CPP was the C preprocessor which processes include files and other directives.
User avatar
MrAl
Posts: 3862
Joined: Fri Jan 11, 2002 1:01 am
Location: NewJersey
Contact:

Post by MrAl »

Hello again,

I havent followed the progress of C into C++ very well, but i too
have read that the name "C++" came from the fact that it was
derived from C and the fact that it has the operator "++" to
increment a variable by 1 as mentioned already.

I think it was originally called "New C" or "C with Classes".

It is interesting how the C name stuck for so long too, even into
C#. Seems there is something catchie about it, like it has a certain
extra appeal of some sort. On the other hand, Fortran sounds like some
sort of machine or something, and Pascal sounds like someones name,
and Cobol sounds like the name of a robot, ha ha.

BTW has anyone here tried the Euphoria language yet?
I am mentioning this because i use it all the time and it is
fairly easy to learn and it does not cost anything, even the
'full' version now, which went Public Domain a few months ago.
In short, it's like a subset of C only with 'sequences'. A sequence
being the main data type where you can store things similar
to arrays in C, only they are much more dynamic and variable
than in C. A drawback is that they are also slower when you use
very very large sequences, depending on how you use them.
The full version (now completely free and open source) allows you
to either run the include files directly (unlike C and C++ and other
languages) without compiling, or you can compile into an .exe
program and run on any machine that supports the platform you
created it for (Windows, Linux, freeBSD, etc.).
Very well worth looking into, especially if you want to create small
programs to do various tasks on your computer and dont feel like
buying the software to do this stuff.
Program examples (all Windows platforms with standard Windows GUIs):

Dictionary for English
Dictionary for Spanish
File rename program
Picture file viewer (jpg, bmp, gif, etc) (very fast too on Windows)
Advanced Engineering calculator for Windows

Currently there is a small group of users.
LEDs vs Bulbs, LEDs are winning.
bwts
Posts: 229
Joined: Tue Jun 11, 2002 1:01 am
Location: britain
Contact:

Post by bwts »

So what does C# stand for?
"Nothing is true, all is permitted" - Hassan i Sabbah
User avatar
MrAl
Posts: 3862
Joined: Fri Jan 11, 2002 1:01 am
Location: NewJersey
Contact:

Post by MrAl »

Hi there,

C# stands for "C sharp", as in the musical note.
I guess it is supposed to sound somehow smarter than C or
something.
LEDs vs Bulbs, LEDs are winning.
pwillard
Posts: 13
Joined: Sat Feb 09, 2002 1:01 am
Contact:

Post by pwillard »

C# is Microsoft's Idea of bringing C to a higher level but it's really C with a .NET flair with a desire to be JAVA.
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests