By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,497 Members | 1,295 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,497 IT Pros & Developers. It's quick & easy.

Clear doubts regarding the C++ Runtime

P: n/a
Hi,

I have been reading some text on C and C++ (i.e advanced books). One
of the books mentioned that C++ requires a runtime support whereas C
does not - what the author was trying to say was that once you compile
a C program the executable created is all that is needed whereas if you
compile a C++ program the executable created requires a C++ runtime
installed on your system to run the program.

Can someone please provide more information on this or could provide a
link to some webiste where this concept is explained in detail. I
would like to know the differences in C and C++ compiled code which
makes a runtime necessary for one and not for the other.

Thanks
Ritesh

Nov 14 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
ritesh wrote:
Hi,

I have been reading some text on C and C++ (i.e advanced books). One
of the books mentioned that C++ requires a runtime support whereas C
does not - what the author was trying to say was that once you compile
a C program the executable created is all that is needed whereas if you
compile a C++ program the executable created requires a C++ runtime
installed on your system to run the program.

Can someone please provide more information on this or could provide a
link to some webiste where this concept is explained in detail. I
would like to know the differences in C and C++ compiled code which
makes a runtime necessary for one and not for the other.

If you mean that it is usual to link shared libraries (such as .so or .dll),
that is true of both C and C++, but C++ requires more of them. 20 years
ago, C implementations which supported only static linking were more common
than now. Static linking will inflate the size of a C++ build much more
than a C build. Reasons for the differences are surely not topical on
c.l.c.
--
Tim Prince
Nov 14 '05 #2

P: n/a
>ritesh wrote:
I have been reading some text on C and C++ (i.e advanced books). One
of the books mentioned that C++ requires a runtime support whereas C
does not ...

In article <OO***************@newssvr21.news.prodigy.com>
Tim Prince <tprince@no_spam_computer.org> wrote:If you mean that it is usual to link shared libraries (such as .so or .dll),
that is true of both C and C++, but C++ requires more of them. ...
I suspect the real question was more about RTTI and/or exception
handling, both of which complicate C++ enormously (compared to C).
Of course, comp.lang.c is the wrong newsgroup on which to discuss
either one.
... Static linking will inflate the size of a C++ build much more
than a C build. Reasons for the differences are surely not topical on
c.l.c.


Indeed.

(In theory, of course, a C++ program that avoids using the RTTI
and exception features -- and much of the rest of C++ along with
them, since, e.g., "new" now throws exceptions -- could compile to
similary-small static-linked binaries. Of course, if one is going
to avoid all these C++ features, I would wonder why that one is
writing C++ code at all. If one simply wants, e.g., the convenience
of variable declaration at point of first use, C99 supports that
already; and quite a few C compilers, while not yet "full C99",
include this now as well.)

Last, a note to the original poster: the phrase "clear doubts", in
English, as used in the subject line means approximately: "these
are things I am pretty sure are wrong", not "could you expound on
something so as to clear up some questions I have". The word
"clear" here takes the role of an adjective, modifying the noun
"doubts", and means "these doubts are clear (i.e., should be obvious
to all)". The word "doubt", in turn, does not translate directly
to "question", but rather to "questionable items" or "dubious
things". The phrase "clear up", in which clear is a verb (rather
than an adjective), *does* mean "answer questions", but the word
"up" is usually required.

English, she is a funny old language. :-)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (4039.22'N, 11150.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #3

P: n/a
Chris Torek wrote:
Tim Prince <tprince@no_spam_computer.org> wrote:
ritesh wrote:

I have been reading some text on C and C++ (i.e advanced books).
One of the books mentioned that C++ requires a runtime support
whereas C does not ...

If you mean that it is usual to link shared libraries (such as
.so or .dll), that is true of both C and C++, but C++ requires
more of them. ...


I suspect the real question was more about RTTI and/or exception
handling, both of which complicate C++ enormously (compared to C).
Of course, comp.lang.c is the wrong newsgroup on which to discuss
either one.
... Static linking will inflate the size of a C++ build much
more than a C build. Reasons for the differences are surely not
topical on c.l.c.


Indeed.

(In theory, of course, a C++ program that avoids using the RTTI
and exception features -- and much of the rest of C++ along with
them, since, e.g., "new" now throws exceptions -- could compile to
similary-small static-linked binaries. Of course, if one is going
to avoid all these C++ features, I would wonder why that one is
writing C++ code at all. If one simply wants, e.g., the convenience
of variable declaration at point of first use, C99 supports that
already; and quite a few C compilers, while not yet "full C99",
include this now as well.)


I think the primary conclusion is that the original "advanced" book
author is woefully misinformed. In fact I would characterize him
as "having his head up where the sun don't shine".

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #4

P: n/a
REH

"ritesh" <ri**********@gmail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
Hi,

I have been reading some text on C and C++ (i.e advanced books). One
of the books mentioned that C++ requires a runtime support whereas C
does not - what the author was trying to say was that once you compile
a C program the executable created is all that is needed whereas if you
compile a C++ program the executable created requires a C++ runtime
installed on your system to run the program.

Can someone please provide more information on this or could provide a
link to some webiste where this concept is explained in detail. I
would like to know the differences in C and C++ compiled code which
makes a runtime necessary for one and not for the other.

Thanks
Ritesh


That's wholly dependent on the implementation. Both languages require
support of a library. Whether that library is statically linked into the
executable or not, depends on your system, not the language. Also,
depending on the platform you are building for, the library may or not
require additional support from the (if existing) OS.

Nov 14 '05 #5

P: n/a

"ritesh" <ri**********@gmail.com> wrote

I have been reading some text on C and C++ (i.e advanced books). One
of the books mentioned that C++ requires a runtime support whereas C
does not - what the author was trying to say was that once you compile
a C program the executable created is all that is needed whereas if you
compile a C++ program the executable created requires a C++ runtime
installed on your system to run the program.

Can someone please provide more information on this or could provide a
link to some webiste where this concept is explained in detail. I
would like to know the differences in C and C++ compiled code which
makes a runtime necessary for one and not for the other.

If I want to create an array in C I would normally do it like this

int *array = malloc(sizeof(int) * N);

in C++ I would do it like this

int *array = new int[N];

(Or these days I would use the standard template library).

So the C code is calling malloc explictly, whilst C++ is probably calling
the same operating system function underneath, but has folded the call into
the language.

Now let's say that I want to port my code to a games console that doesn't
have a malloc() or any OS-defined memory management system.

The C code I can port by writing my own malloc(), and calling that. Or I can
write the code more carefully so that it uses fixed size arrays and doesn't
call malloc() at all.
The C++ code is a bit more difficult. The call to malloc() is hidden in the
language itself. Even if we get rid of all the news, the compiler will still
probably want to know how to implement the keyword. That is probably what
your author means.

However C++ is cleverer than that. It is possible to globally overload the
new and delete operators, so that they call your custom allocation system.
So I suspect your authors are not entirely accurate.
Nov 14 '05 #6

P: n/a
>I have been reading some text on C and C++ (i.e advanced books). One
of the books mentioned that C++ requires a runtime support whereas C
does not - what the author was trying to say was that once you compile
a C program the executable created is all that is needed whereas if you
compile a C++ program the executable created requires a C++ runtime
installed on your system to run the program.
It is possible for both C and C++ to compile with shared libraries
that must be present on the execution system at runtime for the
program to work. This is often the default behavior (e.g. on
FreeBSD and probably on most UNIX systems where shared libraries
are implemented). On most of these systems, it is also possible
to compile static so the executable alone will run when it is copied
to another system. That executable is likely to be a bigger file.

What the author might have meant is that the C libraries are commonly
distributed with the operating system, whereas the C++ aren't. If
so, I'm not sure what platform he's talking about. It may also be
that the author's C++ compiler requires run-time licensing, enforced
by code generated by the C++ compiler.
Can someone please provide more information on this or could provide

a >link to some webiste where this concept is explained in detail.
I >would like to know the differences in C and C++ compiled code
which >makes a runtime necessary for one and not for the other.

MySQL client libraries are not normally distributed with FreeBSD.
If you wish to use C with MySQL on FreeBSD you need to do one of
(a) compile the executable static, or (b) copy the client shared
library to the runtime machine and install it. The same sort of
thing applies to other database client libraries and a lot of other
code that isn't bundled with the OS.

Gordon L. Burditt
Nov 14 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.