user2953119
user2953119

Reputation:

Program in freestanding environment

Quote from 3.6.1/1 N3797:

A program shall contain a global function called main, which is the designated start of the program. It is implementation-defined whether a program in a freestanding environment is required to define a main function.

Are "a program" and "a program in a freestanding environment" different things?

Upvotes: 3

Views: 523

Answers (2)

GoodNameHere
GoodNameHere

Reputation: 51

Yes, a program and a program in a freestanding environment are different things. In freestanding environment you do not have any built-in library to be used.

Upvotes: 0

Nikos Athanasiou
Nikos Athanasiou

Reputation: 31577

C++ is often used in embedded systems programming. There you might encounter a(n example of) lack of "host environment" in which case you're running in a free standing evironment.

What this practically means is that, apart from lack of OS I/O, threading etc libraries is that some facilities are unavailable and it requires assembly start-up code to get you to main(); Characteristic differences (just to get an idea) are

  • Exceptions require code to unwind the stack while looking for an appropriate exception handler to handle the exception. Usually, this code is linked in with your C++ application, but in a freestanding kernel the code must be provided manually.

  • You'd have to write your own heap manager (new/delete) if you wanted to create objects at runtime and your own scheduler if you wanted more than one thread

So considerations, techniques and application domain may vary but a program is a program.

Upvotes: 4

Related Questions