The difference between C and C++

J

Jakob Bieling

I can't find an English one!

I would guess microsoft.public.vc.* are English. Other than those
VC-specific ones, try comp.os.ms-windows.programmer.win32 for
Windows/MFC/etc questions.

Or try the Microsoft news server (see microsoft.com for details, as
I
dont have them handy right now), if you cannot find the MS groups. They
should carry them.

And please, do not top-post and quote properly. Makes reading news
groups a much nicer experience for those reading you posts.

regards
 
C

Calum Grant

Roman said:
(e-mail address removed) napisal(a):



Not at all. When speed is what matters, C is IMHO preferable over C++.

Now that's arguable. The problem with C++ is that it does a lot of
things implicitly, it's quite easy to overlook the costs of some C++
operations.

C++ programmers who need to write optimized code are (or should be)
aware of the costs of C++ operations, and avoid the costly ones.

There are plenty of examples of C++ programs that are faster than C
programs. Consider std::sort() vs qsort(). Also some C++ containers
(e.g. std::map) would be faster than the equivalent C code based upon
void* and function pointers.

In C++ you can also tune the memory allocation (by writing an allocator)
which makes it much easier to write robust, portable, maintainable and
reusable hacks if you want to. It's not that you can't do it in C, it's
just that it would be no faster and just be more work.

Template metaprogramming is a breakthrough in performance that C just
does not have.

Also bear in mind that C++ compilers have been steadily improving,
whereas C compilers have been mature for much longer.

With C++ is that you can program in a C style when that really is the
best, to optimize the 1% of your code that is taking the time, and write
the rest in normal C++ style.

Calum
 
P

persenaama

Why do you believe that there is a speed advantage to using the
preprocessor rather than templates for generic code?

I don't believe such a thing, you misread. If you still have trouble
understanding what I wrote after second reading please ask for
clarifications.

With VC++, l've observed problems where it won't really inline
functions which are declared inline. Did you switch from a
templated inline function or a templated class with inline
functions to macros, and see a speedup?

That is VC++ specific behaviour and not topical at clc++ but I can tell
you that there are compiler specific #pragma's to force inlining to
have more depth in case of recursive meta programs (for example) and
you can try __forceinline keyword, which is also compiler specific.

Like I said, optimizations when specific assembly output or similiar
equivalent are required are toolchain and platform specific. Btw. you
can configure most versions of Visual C++ between 6.0 and 2005 to have
different handling of inline keyword to suit your preferences and
tastes better. If you have problems with your compiler and improving
performance of your software feel free to ask specific questions,
hopefully with concrete code and also don't forget to mention which
compiler and target you are using.

To answer your question: No (and no). Explanation: I don't use
preprocessor macros for function inline expansion. Why: because I write
code in a way that it is not so dependent on particular inlining
invoked or not at compilation time. Only the code that is absolutely
performance critical, I do check compiler output and adjust the code to
achieve the desired result. Again, this is compiler and platform
specific and such code and activity is not what I'd discuess in this
particular group.
 
N

Neil Cerutti

It's more a question of style. Some code is obviously C code,
even though it is compilable with a C++ compiler. Compare these
simple snippets:

For example, Kernighan & Pike _The Practice of Programming_
contains numerous examples of C code, which were compiled with a
C++ compiler by the authors, to double-check them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,196
Latest member
ScottChare

Latest Threads

Top