c runtime

J

john sun

Hello all,

I know c run time term, and also I use c run time lib. But I still confused
about what's the c run time? Is there run time environment created before
loading the c/c++ program? If there is, what's its functionality ? Someone
can give me a detailed and system explanation or give a good link to address
this issue? Thanks very very much!

John Sun
 
D

Dan Pop

In said:
I know c run time term, and also I use c run time lib. But I still confused
about what's the c run time? Is there run time environment created before
loading the c/c++ program?

It is created before executing the main function of the C program.
If there is, what's its functionality ?

At the very least, it must create the argv array and call main() in such
a way that returning from its initial invocation has the same effect as
calling exit() with its return value. This can be trivially achieved
with:

exit(main(argc, argv));

If the compiler relies on the CPU being initialised in a certain way
(e.g. the FP rounding mode, denormal handling or FP exception handling),
this initialisation must also take place before main() is called.

Some of the library functions may also require certain initialisations
to be performed before main() is executed (e.g. the setup of the malloc
and friends arena).

When people talk about the C run time, they usually refer to the C run
time support provided by the implementation, i.e. the startup module doing
the jobs described above and the libraries available to a C program.

The C run time environment is a more complex concept, depending on how the
implementation works: by compiling C into machine code or by interpreting
it. In the former case, the C run time environment consists of the C run
time support and the OS under which the program runs. In the latter,
there is an additional software layer between the C program and the OS,
whose existence is needed because usual computers cannot execute C code
directly.

Dan
 
R

Richard Heathfield

john said:
Hello all,

I know c run time term, and also I use c run time lib. But I still
confused about what's the c run time? Is there run time environment
created before loading the c/c++ program?

Assuming you mean the C program, the answer is: yes.
If there is, what's its functionality ?

What do you think calls main()? :)
 
M

Mark A. Odell

Hello all,

I know c run time term, and also I use c run time lib. But I still
confused about what's the c run time? Is there run time environment
created before loading the c/c++ program?

Yes. C++ is not C. A minimal C run-time would at least clear unitialized
variables (sometimes called BSS) and set initialized variables with their
initial values (sometimes called DATA). At some point the C run-time code
will call main() with proper arg. support and handle a return from main()
or exit() call.
 
D

Dan Pop

In said:
Yes. C++ is not C. A minimal C run-time would at least clear unitialized
variables (sometimes called BSS) and set initialized variables with their
initial values (sometimes called DATA).

On typical hosted implementations, this is the OS's job, when loading the
executable image from the disk and it is not something language specific.

Dan
 
M

Mark A. Odell

On typical hosted implementations, this is the OS's job, when loading
the executable image from the disk and it is not something language
specific.

You are correct. If only I had an OS on my microcontrollers to do this for
me. I do not find implementing the C run-time support particularly
interesting.
 
D

Dan Pop

In said:
You are correct. If only I had an OS on my microcontrollers to do this for
me. I do not find implementing the C run-time support particularly
interesting.

It should provide you with a lot of insight about the microcontrollers
you're programming on, insight that should be useful when writing your
applications. Especially if you have to meet execution time and/or
program size constraints.

Dan
 

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
474,137
Messages
2,570,797
Members
47,342
Latest member
eixataze

Latest Threads

Top