Click here to Skip to main content
15,887,214 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
Gary Wheeler21-Dec-23 7:06
Gary Wheeler21-Dec-23 7:06 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
honey the codewitch21-Dec-23 7:08
mvahoney the codewitch21-Dec-23 7:08 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
CPallini21-Dec-23 7:41
mveCPallini21-Dec-23 7:41 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
honey the codewitch21-Dec-23 7:42
mvahoney the codewitch21-Dec-23 7:42 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
CPallini21-Dec-23 10:25
mveCPallini21-Dec-23 10:25 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
honey the codewitch21-Dec-23 10:26
mvahoney the codewitch21-Dec-23 10:26 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
megaadam21-Dec-23 11:55
professionalmegaadam21-Dec-23 11:55 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
jschell22-Dec-23 6:44
jschell22-Dec-23 6:44 
honey the codewitch wrote:
Interestingly you can call main() from inside your C app, but not in C++.


Odd.

Took me a bit to find a reference. Following seems to be best I could find.

Use the index to find '3.6' the click on page number. The first section there is the relevant one.

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf

"The function main shall not be used within a program. The linkage(3.5) of main is implementation-defined.
A program that defines main as deleted or that declares main to be inline, static, or constexpr is ill-formed. The name main is not otherwise reserved."


Although a draft I did find other mentions to this so I suspect is it substantially correct. Also other references suggest the updated spec matches (2014 to C14).

However I think the language of that is not as precise as some might think.

Since the linkage is not defined that means a compiler is free to do whatever it wants with it.

And the easiest way to handle that is to link it. Why? Because if it doesn't link it then it must figure out that the specific function is in fact the real entry point versus some other legitimate variation. Easier to just ignore the issue - which is allowed.

Also note that this restriction was added with newer versions of the spec. The original ANSI spec did not have any subsections in 3.6 at all.

-------------------------------------------------
Found the following also. See the second reply.

https://stackoverflow.com/questions/2128321/can-main-function-call-itself-in-c[^]

I didn't verify that one but the response suggests that the compiler is not responsible for telling you that you should not be calling main.

That is another one of things that as a compiler writer should not worry about. There are other things they should spend their time on to get right.
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
honey the codewitch22-Dec-23 6:48
mvahoney the codewitch22-Dec-23 6:48 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
jschell22-Dec-23 6:51
jschell22-Dec-23 6:51 
AnswerRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
englebart21-Dec-23 5:28
professionalenglebart21-Dec-23 5:28 
AnswerRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
Gerry Schmitz21-Dec-23 8:02
mveGerry Schmitz21-Dec-23 8:02 
AnswerRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
glennPattonWork322-Dec-23 1:16
professionalglennPattonWork322-Dec-23 1:16 
AnswerRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
mdblack9822-Dec-23 2:10
mdblack9822-Dec-23 2:10 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
Owen Lawrence22-Dec-23 5:19
Owen Lawrence22-Dec-23 5:19 
AnswerRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
Juan Pablo Reyes Altamirano22-Dec-23 5:49
Juan Pablo Reyes Altamirano22-Dec-23 5:49 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
jschell22-Dec-23 7:09
jschell22-Dec-23 7:09 
AnswerRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
Ralf Quint22-Dec-23 7:27
Ralf Quint22-Dec-23 7:27 
AnswerRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
Member 1616867422-Dec-23 13:35
Member 1616867422-Dec-23 13:35 
AnswerRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
sx200826-Dec-23 19:17
sx200826-Dec-23 19:17 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
jschell27-Dec-23 5:59
jschell27-Dec-23 5:59 
GeneralRe: ( C/C++ historical question) was there a point in time where adding a return at the end of a void function was required ? Pin
sx200829-Dec-23 16:59
sx200829-Dec-23 16:59 
QuestionGood alternatives to STM32CubeIDE? Pin
CPallini21-Dec-23 1:03
mveCPallini21-Dec-23 1:03 
AnswerRe: Good alternatives to STM32CubeIDE? Pin
Mike Hankey21-Dec-23 3:24
mveMike Hankey21-Dec-23 3:24 
GeneralRe: Good alternatives to STM32CubeIDE? Pin
CPallini21-Dec-23 3:32
mveCPallini21-Dec-23 3:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.