473,320 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

c / c++ : is it end of era ?

I started programming with c. Lot of projects are being done in C++. We
have to move in THE C++.
I read around 3 - 4 books (including Faqs, stroustrup) on c++. What i
found in most of the book is that they criticize c language and c
programmer. And they silently run away from good feature of C.
They have sentence like , "you have to unlearn c to learn C++".

is it the end of C era ?
Stroustrup and writers of Faqs are gurus of technologies. These people
are commenting on C language.
should we believe them?
somewhere it is demoralizing for c programmer.

I just wanted to know what other people thinks on this .

Dec 26 '06
167 5417
Richard Heathfield a écrit :
jacob navia said:

>>Dik T. Winter a écrit :

<snip>

>>>If the result is not used, gcc removes the call, even
with -O0.

I see that as a bug. Why it removes things when not
asked for optimizations???


The Standard doesn't require it not to, so it's not a bug.
It is, since we are calling memchr and strchr not
for their result but for their side-effects.

It has a wrong table of functions without side-effects
and thinks that they can be only called for
their results.

We are calling it for their side effects: they take
time to do their stuff, and that table it has is
WRONG.

Jan 2 '07 #151
jacob navia wrote:
Dik T. Winter a écrit :
>In article <45***********************@news.orange.frjacob navia <ja***@jacob.remcomp.frwrites:
...
> The additions to the variable "c" disable any optimization
of the calls away. Besides, main returns that value
and this means that gcc must generate the code as told.

The variable c is not needed for that. It is sufficient that the return
value of the function is used in some way (e.g.
if(strcgr(s, '1'));
is sufficient). If the result is not used, gcc removes the call, even
with -O0.

I see that as a bug. Why it removes things when not
asked for optimizations???
Why not, if it's not relevant to the program's result?

The border between "optimisation" and "unstupid code generation" is
a wide and fuzzy one.
In a more philosophical mood, I think a compiler
is a TRANSLATOR of MY program, not something
that translates my program as it thinks I should have written
it...
A good translator will produce a result that efficiently reflects
the intended effect of the original. If that translation isn't
a trivial composition of trivial sub-translations, so much the
worse for trivia.

--
Chris "HO. HO. HO." Dollin
"The path to the web becomes deeper and wider" - October Project

Jan 2 '07 #152
jacob navia said:
Richard Heathfield a écrit :
>jacob navia said:
>>>Dik T. Winter a écrit :
<snip>
>>>>If the result is not used, gcc removes the call, even
with -O0.

I see that as a bug. Why it removes things when not
asked for optimizations???

The Standard doesn't require it not to, so it's not a bug.

It is, since we are calling memchr and strchr not
for their result but for their side-effects.
The Standard does not specify any side effects for either memchr or strchr,
so the fault is with the programmer who expects such side effects to occur.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jan 2 '07 #153
jacob navia <ja***@jacob.remcomp.frwrites:
Richard Heathfield a écrit :
>jacob navia said:
>>>Dik T. Winter a écrit :
<snip>
>>>>If the result is not used, gcc removes the call, even
with -O0.

I see that as a bug. Why it removes things when not
asked for optimizations???
Because the result of the call is not used.
>The Standard doesn't require it not to, so it's not a bug.

It is, since we are calling memchr and strchr not
for their result but for their side-effects.

It has a wrong table of functions without side-effects
and thinks that they can be only called for
their results.

We are calling it for their side effects: they take
time to do their stuff, and that table it has is
WRONG.
What side effects?

Show us a program whose *visible* behavior when compiled under gcc is
inconsistent with the requirements of the standard. (Remember that
the standard doesn't impose any timing requirements.) If you can do
that, you'll have found a bug, assuming you've invoked gcc in a
conforming mode.

If you write
x = x + 1;
do you want the compiler (if invoked in a "non-optimizing" mode) to
generate code to load the value of x, load the value 1, add them, and
store the result back in x? Or would you be satisfied if it generated
a single increment instruction that achieves exactly the same thing?
Do you insist on distinct generated code for each of the following:
x = x + 1;
x += 1;
x ++;
++ x;
or are willing to accept the compiler's author's judgement that
they're all semantically identical?

Compilers can perform some optimizations (i.e., not-quite-literal
translations of source code to object code) even if you don't ask for
optimization. In my opinion, there's nothing wrong with this, but of
course you're entitled to your own contrary opinion. What is *not* a
matter of opinion, though, is that this does not violate the standard.

Apparently the authors of gcc felt that this optimization was easy and
safe enough to do in "-O0" mode. They apparently didn't feel it was
necessary to cater to the tiny minority of programs whose behavior
depends on wasted CPU time. I tend to agree with them.

memchr() and strchr() have no side effects (unless you consider
wasting CPU time to be a side effect), and the compiler is under no
obligation to generate code that merely wastes CPU time if the result
is not used. If you want gcc to have a mode in which function calls
are never optimized away, take it up with the gcc maintainers (try
gnu.gcc.bug) -- or just write code that uses the result so gcc *can't*
optimize the calls away (which is what you did later anyway).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jan 2 '07 #154
jacob navia wrote:
Keith Thompson a écrit :
<snip>
strchr() has to check for '\0' on each iteration of the loop. A
counted strings implementation has to check whether the index exceeds
the length on each iteration of the loop. My guess is that strchr()
is going to be slightly faster -- but that's only a guess, and it's
likely to vary on different implementations.

No. The big difference is that byte scan is hardwired in some
processors, what makes it considerably FASTER than
searching for a zero byte OR the searched character
are you *sure* about that? Just because an instruction set includes
a memcpy doesn't mean its faster than using multiple instructions.
Such an instruction begins to look very CISC like. I believe the VAX
had an instruction to calculate an arbitary CRC. Modern designs
don't.

I'm pretty sure the Z80 byte copy was *slower* than hand coded
instructions.

--
Nick Keighley

Jan 3 '07 #155
"jacob navia" <ja***@jacob.remcomp.frwrote in message
news:45***********************@news.orange.fr...
No. The big difference is that byte scan is hardwired in some
processors, what makes it considerably FASTER than
searching for a zero byte OR the searched character
You're living in the 70s and 80s. No instruction is "hardwired" in
modern CISC chips; they're decoded into RISC instructions. A "byte
scan" instruction may well execute slower than writing your own loop
because the microcode engine isn't all that fast (and, in some chips,
has a rather low output rate and stalls other decoding that would
otherwise happen at the same time). It's not a guaranteed win.

For the same reason, modern compilers skip the x86 ENTER/LEAVE
instructions in favor of emitting their own prolog/epilog, except when
optimizing for size. Ditto for nearly every other microcoded
instruction; they're just slow. And, of course, this causes a vicious
cycle; CPU designers don't optimize that part of the chip because
compilers don't use those instructions. Lather, rinse, repeat...

S

--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking
--
Posted via a free Usenet account from http://www.teranews.com

Jan 3 '07 #156
In article <45**********************@free.teranews.com>,
Stephen Sprunk <st*****@sprunk.orgwrote:
>You're living in the 70s and 80s. No instruction is "hardwired" in
modern CISC chips; they're decoded into RISC instructions. A "byte
scan" instruction may well execute slower than writing your own loop
because the microcode engine isn't all that fast (and, in some chips,
has a rather low output rate and stalls other decoding that would
otherwise happen at the same time). It's not a guaranteed win.
>For the same reason, modern compilers skip the x86 ENTER/LEAVE
instructions in favor of emitting their own prolog/epilog
Aren't ENTER and LEAVE slower because they implement a function call
protocol more complicated than that usually required, rather than for
the reasons you listed? In particular, they can handle "displays" as
used for nested procedures, and provide a frame pointer which can
often be omitted.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Jan 3 '07 #157
In article <11**********************@73g2000cwn.googlegroups. com>,
shaanxxx <sh******@yahoo.comwrites
>I started programming with c. Lot of projects are being done in C++. We
have to move in THE C++.
I read around 3 - 4 books (including Faqs, stroustrup) on c++. What i
found in most of the book is that they criticize c language and c
programmer. And they silently run away from good feature of C.
They have sentence like , "you have to unlearn c to learn C++".

is it the end of C era ?
Stroustrup and writers of Faqs are gurus of technologies. These people
are commenting on C language.
should we believe them?
somewhere it is demoralizing for c programmer.

I just wanted to know what other people thinks on this .
The use of C died out a bit in the PC world but in the (much larger and
still growing) embedded world C is still the main language. There is
also some use of C++

C++ came from C90.
C has moved on and diverged from that point
C++ also moved on but in a different direction.
Therefore C and C++ look similar but may do different things even where
the syntax is similar.

C is a modular/structured language C++ is OO and as such needs a
different mindset for the design of programs.

Whilst C is still going strong C++ is loosing out to Java, C# and
C++/CLI so C++ may die out (or rather evolve) before C does.
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Jan 4 '07 #158
Chris Hills said:

<snip>
C++ came from C90.
Nit: C++ pre-existed C90 by several years.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jan 4 '07 #159
In article <po******************************@bt.com>, Richard Heathfield
<rj*@see.sig.invalidwrites
>Chris Hills said:

<snip>
>C++ came from C90.

Nit: C++ pre-existed C90 by several years.
C++ started evolving before 1990 but it fixed on the C90 standard as a
basis . Look in your copy of the C++ standard.

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Jan 4 '07 #160
Chris Hills said:
In article <po******************************@bt.com>, Richard Heathfield
<rj*@see.sig.invalidwrites
>>Chris Hills said:

<snip>
>>C++ came from C90.

Nit: C++ pre-existed C90 by several years.

C++ started evolving before 1990 but it fixed on the C90 standard as a
basis .
I guess it depends on what you mean by "came from", then. Yes, you can argue
that C++ "came from" C90, in much the same sense that Doctor Foster "came
from" Gloucester - but first he had to go there!

C++ came from K&R C, headed off on its own for some adventure, excitement,
and really wild things, and then went to C90 for a 10,000 mile service
before heading off into the sunset again.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jan 4 '07 #161
Chris Hills <ch***@phaedsys.orgwrites:
C++ came from C90.
Not really. C90 is K&R C with influence from C++ (prototypes, which is the
most visible difference between K&R C and C90, is directly imported from
C++).

Yours,

--
Jean-Marc
Jan 4 '07 #162
"Richard Tobin" <ri*****@cogsci.ed.ac.ukwrote in message
news:en***********@pc-news.cogsci.ed.ac.uk...
In article <45**********************@free.teranews.com>,
Stephen Sprunk <st*****@sprunk.orgwrote:
>>For the same reason, modern compilers skip the x86 ENTER/LEAVE
instructions in favor of emitting their own prolog/epilog

Aren't ENTER and LEAVE slower because they implement a function call
protocol more complicated than that usually required, rather than for
the reasons you listed? In particular, they can handle "displays" as
used for nested procedures, and provide a frame pointer which can
often be omitted.
The standard calling convention on x86 is what ENTER/LEAVE do. However,
emitting separate instructions allows some bits to be omitted,
rearranged, removed, etc. as the optimizer sees fit. Note that when
optimizing for size, ENTER/LEAVE _are_ used; they couldn't be if they
didn't have the same net effect.

Dropping the frame pointer requires a specific, extra command line flag
to the compiler because it breaks debuggers; it's generally a bad idea,
so it's off by default even at the highest optimization levels. You
typically only turn it on for particular functions or libraries that
need the extra speed from having another register, and there's few
things that need such so badly that people are willing to give up
debugging capability.

I don't know what "displays" for nested procedures are.

S

--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking
--
Posted via a free Usenet account from http://www.teranews.com

Jan 4 '07 #163
In article <45**********************@free.teranews.com>,
>I don't know what "displays" for nested procedures are.
According to the Intel manual I have, "The second operand [of ENTER]
(nesting level operand) gives the lexical nesting level (0 to 31) of
the procedure. The nesting level determnines the number of stack frame
pointers that are copied to the 'display area' of the new stack frame
from the prededing frame".

In a language where you can nest procedures, something like:

int foo(void)
{
int a;

int bar(int x)
{
... reference to a ...;
if(x 0)
bar(x-1);
...;
}

bar(10);

...;
}

then a procedure may need be able to access variables which are in an
enclosing procedure's stack frame, and which may not be in a fixed
position on the stack relative to its own frame (as in the recursive
call to bar above). A display is a structure that makes this work by
recording the stack frame pointers of the visible activations of
enclosing procedures.

C doesn't need this, but the implementation of ENTER has to test for
it. Of course, CPU designers may nowadays be able to optimise this
away without overhead.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Jan 4 '07 #164
In article <45**********************@free.teranews.com>,
Stephen Sprunk <st*****@sprunk.orgwrote:
>Dropping the frame pointer requires a specific, extra command line flag
to the compiler because it breaks debuggers;
By the way, it's quite possible to debug without a frame pointer. The
frame pointer will always be "close" to the stack pointer, and its
offset will be fixed at a given point in the code. The compiler can
record the necesary information in the executable file so that a
debugger can construct a "virtual" frame pointer. Of course this
requires a little more cooperation between compiler and debugger.

Even more off-topic: this is reminiscent of the way the Java VM
provides exception-catching without any run-time overhead.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Jan 5 '07 #165
Mark McIntyre <ma**********@spamcop.netwrites:
On Fri, 29 Dec 2006 09:36:08 +0100, in comp.lang.c , jacob navia
<ja***@jacob.remcomp.frwrote:
>>And you are speaking about something you do not know at all: me.

Au contaire, cheri.
>>Where is your data about me? Where you know what experience I have or
not?

You've demonstrated your experience in this newsgroup on numerous
occasions. If you have different experience to that which you display
here, then show it.
>>You don't. Period. The one making sweeping statements is you.

I'm not the one making sweeping statements claiming that it is
essential to know the length of a string.
>>How do you pass the length of the string then?

With correct design, you don't need to .
Ridiculous. If the example of padding all strings to be FIXEDBUFF in
length or whatever is your idea of correct design then either something
is wrong or you are purposely rising Jacob.

Strings are frequently copied into correctly sized memory blocks to
avoid multiple program objects holding pointers to single string
resources.

Having said that, it would be rare in this case than a simple strlen
wouldnt be better than keeping the length as an attribute.

Having said that, many languages do do this so there must be something
to be said for it.
>
>>No, you need merely know that it cannot be larger than the buffer. I
don't expect you to understand the difference.

Gosh! You are clever. And how can I know if the given string
is bigger than the buffer without at least trying to measure
the length?

By knowing its length already, of course.
>>int fn(char *str)
{
char tmpbuf[512];
/* Here I have to start scanning the string.
At least 511 bytes must be scanned before
I realize that the length of the string is bigger
than tmpbuf. For bigger buffers a bigger WASTE
*/
}

Is it /my/ fault if you have a badly designed programme? Where did
"str" come from? How did you create it? Did you define its length when
you did so?

To put you out of your misery, the app in question read strings into
fixed length buffers, padded them with blanks and null-terminated
them. Thus the strings were /always/ exactly N characters long, no
more and no less. This removed any need at all anywhere to calculate
how long the strings were, because we already knew.
>>If you need to handle div/0 sometimes, why always perform the check?

Because you never know when software will change and a constant
becomes a variable...

Two points here
a) constants have nothing to do with it.
b) designing an application for a series of unknown future changes for
unguessable purposes by maintenance droids of unknown quality is both
inefficient and foolish.
I also strongly suspect you're not a follower of XP. They'd shoot you
for doing that sort of thing. :-)
>>In point of fact it hurt considerably because our pricing calculator
was slower than everyone else's to the extent that we missed deals.

Ahh and it was slower because of the division by zero tests?

Yes. How do I know? I measured it. Next question.
>>I would like to see the data that supports that hypothesis.

Sure. Get yourself employed by my former employer, and you can look at
my project post-implementation report. Its in the files of the
Technology Dept somewhere.
>>With today's machines, a test for zero is so fast

And you've proved this beyond all doubt on Vax/VMS, Vax/OSF,
Sun/Solaris, Windows NT/PIII, all of which were targets.
>>that to slow
down a calculator so that a human being notices the tests must have
been done in an incredible fashion,

Or incredibly often. You apparently have no experience of numerical
pricing techniques either. Ever heard of monte-carlo simulation?
>>>>Yes, it may be 0.0001% less efficient but maybe he did not see
"efficiency" as a higher goal than SECURITY!!!

Now you're being silly. Only an idiot makes remarks like that.

Obvious coming from you.

The point you miss is that security and efficiency are not mutually
exclusive, nor is one axiomatically more important than the other.
Again you generalise unacceptably.
>>This finishes it. You, you are not AN IDIOT!

I'm glad we agree I'm not an idiot. I know that of course.
--
Jan 8 '07 #166
Keith Thompson <ks***@mib.orgwrites:
jacob navia <ja***@jacob.remcomp.frwrites:
[...]
>I have implemented operator overloading in the lcc-win32
coimpiler system. I think it is an improvement to C, without
incurring with all the associated costs of C++.

But it isn't C. Do you understand that?
In what language has he implemented these mongrel extensions?
Jan 8 '07 #167
Richard said:
Keith Thompson <ks***@mib.orgwrites:
>jacob navia <ja***@jacob.remcomp.frwrites:
[...]
>>I have implemented operator overloading in the lcc-win32
coimpiler system. I think it is an improvement to C, without
incurring with all the associated costs of C++.

But it isn't C. Do you understand that?

In what language has he implemented these mongrel extensions?
The implementation language is irrelevant. A C compiler could be written in
Fortran 77 or SNOBOL for all the C Standard cares.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jan 8 '07 #168

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL)...
2
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues...
3
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which...
0
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. ...
1
by: Richard Galli | last post by:
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the...
4
by: Albert Ahtenberg | last post by:
Hello, I have two questions. 1. When the user presses the back button and returns to a form he filled the form is reseted. How do I leave there the values he inserted? 2. When the...
1
by: inderjit S Gabrie | last post by:
Hi all Here is the scenerio ...is it possibly to do this... i am getting valid course dates output on to a web which i have designed ....all is okay so far , look at the following web url ...
2
by: Jack | last post by:
Hi All, What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g. select x from y where z=:parameter Which in asp/jsp would be followed by some statements to bind a value...
3
by: Sandwick | last post by:
I am trying to change the size of a drawing so they are all 3x3. the script below is what i was trying to use to cut it in half ... I get errors. I can display the normal picture but not the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.