Re: Simplicity has a future



"Tomás" <No.Email@Address> writes:
Keith Thompson posted:
"Tomás" <No.Email@Address> writes:
[...]
I can copy-paste your C code and compile it as C++. If my version is
any slower or uses less memory, I'll eat my hat.

int main(void)
{
int new;
return 0;
}

Smart. If pedantry is what you're after, then:

If I copy-paste your C code, and then go through it for:

(a) Use of C++ keywords

(b) Inconsistencies between C and C++

And then compile it, I guarantee that the C++ version won't be slower or
require more memory.

I agree that it's very likely, but I don't see how you can guarantee
it without a lot more caveats.

If I run the program on a faster computer than you do, mine will
probably be faster than yours. If I use a better compiler than you
do, mine will likely be faster than yours. Many compiler suites that
include C and C++ compilers use different frontends for the two
languages; the C frontend might happen to generate better code than
the C++ frontend.

All else being equal, there's no reason I know of to assume that a
program written in the common subset of C and C++ will be more
efficient when compiled as C than when compiled as C++ (or vice
versa). I'm not confident enough of that to offer to consume any
headgear.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <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.
.



Relevant Pages

  • Re: right padding
    ... Using gcc in mingw on a windows machine.. ... helpful things a compiler can do if you are writing library code like ... int num = 123; ... area of memory freed is the area that was allocated in the subroutine. ...
    (comp.lang.c)
  • Re: data types
    ... Usually short is smaller than an int. ... memory per dms structure if they are 32-bit integers. ... current compiler system. ... recommend either a version of gcc,, or Visual Studio ...
    (comp.lang.c)
  • Re: Storing an integer: why "int"?
    ... > padding bytes between them to satisfy alignement requirements. ... > short int A; ... > So in theory you are right: short may use less memory. ... > by means of some pragma or compiler option. ...
    (comp.lang.cpp)
  • Re: not declaring something to equal null
    ... int i = null; and instead just say ... the c compiler just grabs a bit of memory equivalent to however big ... remember being told that in C, when you allocate some memory, the ... compiler to warn you about things it otherwise wouldn't be able to. ...
    (comp.lang.c)
  • Re: Intel Atom vs ARM
    ... I have a vague memory that there were some systems where the system C ... compiler had 16-bit int anyway. ... for 68000 systems when compiled with 16-bit int types, ...
    (comp.arch)