[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Sheflug] c++ & mem



>     Al> Old code, yes, efficient code? I don't think I necessarily
>     Al> agree with that.  Efficient, maybe, if the coder is a C coder
>     Al> who doesn't do so much C++. C++ overall is generally much
>     Al> nicer to streamline than C code.
>
> By "efficient code" I meant things like unrolling loops by hand
> (Duff's device -- a compiler can _never_ get that right because
> compilers don't read hardware data sheets),

I really don't see why a compiler can't unroll a loop? That's not exactly
hard. I'm not really sure what the hardware data sheet has to do with
things, either.

> short-circuiting the
> virtual function call mechanism when you know which type you're going
> to have, defining multiple hand-tweaked versions of linked lists
> rather than deriving from a single "class link { link *next; union {
> void *object; anything_small_enough_to_fit_in_a_void*'s_storage
> thing;};}" (or better using something from a standard class library)
> and such-like.  No-nos in well-styled C++.

No-nos how? The idea is that the compiler does this, not the human
programmer. A compiler generates vastly better asm code, and can do
intelligent stuff with regards to choosing specialisations, etc.

>     Al> No, I disagree completely. If you're planning on programming
>     Al> in C++, you need to test the compiler *with* C++, not C - that
>     Al> means the libraries, etc.
>
> You need to reread chapter one of K&R again, I see.

Really...

> Case in point: the original poster did not need to use libstdc++ to
> run into problems.  And the kind of problems he had are typically
> harder to solve by email than actual language issues; eg, no DOS
> person would ever have figured out the actual problem since DOS always
> includes . in %PATH.
>
> OTOH, if he'd written the program using iostreams, a lot of the advice
> would have focused on getting that library working, right?

Nope, you've missed the point. I wasn't arguing that having a C++ example
not working would have led to a quicker solution, nor was I arguing that the
initial advice given would have changed had the test case been different. At
least three people offered the correct solution to the initial problem; I
was more offering general advice for the future - if you want to program in
C++, you need a g++ dev environment. The initial problem was compunded by
the fact that the author of the test program had reused the name of a
built-in, hence no "Command not found" type warning - even a DOS person
would have caught that, had it been a.out, helloworld, etc.

Cheers,

Alex.

---------------------------------------------------------------------
Sheffield Linux User's Group - http://www.sheflug.co.uk
To unsubscribe from this list send mail to
- <sheflug-request [at] vuw.ac.nz> - with the word 
 "unsubscribe" in the body of the message. 

  GNU the choice of a complete generation.