Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yes, in hosted environment it is UB, unless the implementation specifies otherwise. Relevant quotes from N1256:

1. In this International Standard, "shall" is to be interpreted as a requirement on an implementation or on a program;

2. If a "shall" or "shall not" requirement that appears outside of a constraint is violated, the behavior is undefined.

3. (5.1.2.2) A hosted environment need not be provided, but shall conform to the following specifications if present.

4. (5.1.2.2.1) The function called at program startup is named main. The implementation declares no prototype for this function. It shall be defined with a return type of int and with no parameters:

    int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names may be used, as they are local to the function in which they are declared):

    int main(int argc, char *argv[]) { /* ... */ }
or equivalent; or in some other implementation-defined manner.

5. (J.2 Undefined behavior) - A program in a hosted environment does not define a function named main using one of the specified forms (5.1.2.2.1).



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: