Is int main (int, char const * const *)?

According to the C ++ 11 standard, is the following program well-formed and portable C ++?

int main(int argc, char const* const* argv) {} 
+6
source share
2 answers

Not. In a pure C ++ portable program, the argv argument, if present, does not have const modifiers.

Edit: See section 3.6.1.2 of the draft C ++ 11 standard, which (in the version I have in mind):

Implementation should not predetermine the main function. This feature should not be overloaded. It must have a return type of int, but otherwise its type is determined by the implementation. All implementations must allow both of the following definitions of main:

int main(){ /*...*/ }

and

int main(int argc, char* argv[]) { /* ... */ }

+11
source

Depends on what you mean by figurative. An evil C ++ implementation may reject it on the grounds that its signature int(int,char const*const*) is different from one of the required allowed signatures int() and int(int,char**) . (An evil implementation might seemingly reject auto main(int argc,char* argv[]) -> int or, indeed, any definition of main , where the body is not { /* ... */ } )

However, this is not typical. I don’t know of any implementations when adding a constant will cause a problem with calling main , and since C ++ 11 added a bit about “similar” types, you will not violate the strict anti-aliasing rule when accessing a char** object via char const * const * variable char const * const * .

Thus, although the corresponding implementation may technically abandon it, I think that it will be portable for any implementation that you might want to use.

+3
source

Source: https://habr.com/ru/post/919075/


All Articles