$ gcc --version
gcc (GCC) 14.2.1 20240912 (Red Hat 14.2.1-3)
$ g++ -O3 -o /tmp/a /tmp/a.cpp
/tmp/a.cpp:4:1: warning: 'int main(int, const char**, const char**, const char**)' takes only zero or two arguments [-Wmain]
4 | main(int argc, const char **argv, const char **envp, const char **auxv)
| ^~~~
So much for backward compatibility and support for the original C++ operating environment (unix).
$ gcc --version
gcc (GCC) 14.2.1 20240912 (Red Hat 14.2.1-3)
$ g++ -O3 -o /tmp/a /tmp/a.cpp /tmp/a.cpp:4:1: warning: 'int main(int,
const char**, const char**, const char**)' takes only zero or two
arguments [-Wmain]
4 | main(int argc, const char **argv, const char **envp, const char
**auxv)
| ^~~~
So much for backward compatibility and support for the original C++
operating
environment (unix).
On 2/2/2025 10:05 AM, Scott Lurndal wrote:
$ gcc --version
gcc (GCC) 14.2.1 20240912 (Red Hat 14.2.1-3)
$ g++ -O3 -o /tmp/a /tmp/a.cpp
/tmp/a.cpp:4:1: warning: 'int main(int, const char**, const char**, const char**)' takes only zero or two arguments [-Wmain]
4 | main(int argc, const char **argv, const char **envp, const char **auxv)
| ^~~~
So much for backward compatibility and support for the original C++ operating
environment (unix).
What is auxv? I've used envp, but never auxv.
On 2/2/2025 10:05 AM, Scott Lurndal wrote:
$ gcc --version
gcc (GCC) 14.2.1 20240912 (Red Hat 14.2.1-3)
$ g++ -O3 -o /tmp/a /tmp/a.cpp
/tmp/a.cpp:4:1: warning: 'int main(int, const char**, const char**, const >char**)' takes only zero or two arguments [-Wmain]
4 | main(int argc, const char **argv, const char **envp, const char >**auxv)
| ^~~~
So much for backward compatibility and support for the original C++ operating
environment (unix).
What is auxv? I've used envp, but never auxv.
On 2/2/25 13:05, Scott Lurndal wrote:
$ gcc --version
gcc (GCC) 14.2.1 20240912 (Red Hat 14.2.1-3)
$ g++ -O3 -o /tmp/a /tmp/a.cpp /tmp/a.cpp:4:1: warning: 'int main(int,
const char**, const char**, const char**)' takes only zero or two
arguments [-Wmain]
4 | main(int argc, const char **argv, const char **envp, const char
**auxv)
| ^~~~
So much for backward compatibility and support for the original C++
operating
environment (unix).
Does it prevent the code from compiling and executing correctly in a
Unix environment? If not, it has no effect on the backwards
compatibility of the compiler.
Those are the only two forms that all implementations of C and C++ are >required to accept, though they are allowed to accept additional >implementation-defined forms. Those statements have been true of both >languages for as long as they've been standardized.
This is only a warning - fully conforming implementations are allowed to
warn about anything they want, such as failing to use taboo words for >user-defined identifiers.
The warning is the default for C++, and is turned on by -Wall and
-Wpedantic for C, because it's a reasonable thing to warn about. But if
you disagree with that assessment, it can be turned off by -Wno-main
scott@slp53.sl.home (Scott Lurndal) writes:
$ gcc --version
gcc (GCC) 14.2.1 20240912 (Red Hat 14.2.1-3)
$ g++ -O3 -o /tmp/a /tmp/a.cpp
/tmp/a.cpp:4:1: warning: 'int main(int, const char**, const char**, const char**)' takes only zero or two arguments [-Wmain]
4 | main(int argc, const char **argv, const char **envp, const char **auxv)
| ^~~~
So much for backward compatibility and support for the original C++ operating
environment (unix).
Backward compatibility is exactly what you're seeing here.
James Kuyper <jameskuyper@alumni.caltech.edu> writes:
Those are the only two forms that all implementations of C and C++ are >>required to accept, though they are allowed to accept additional >>implementation-defined forms. Those statements have been true of both >>languages for as long as they've been standardized.
This is only a warning - fully conforming implementations are allowed to >>warn about anything they want, such as failing to use taboo words for >>user-defined identifiers.
The warning is the default for C++, and is turned on by -Wall and >>-Wpedantic for C, because it's a reasonable thing to warn about. But if
you disagree with that assessment, it can be turned off by -Wno-main
My problem is that g++ never warned until recently, so it broke a build
that used -Werror.
Am 02.02.2025 um 19:05 schrieb Scott Lurndal:
$ gcc --version
gcc (GCC) 14.2.1 20240912 (Red Hat 14.2.1-3)
$ g++ -O3 -o /tmp/a /tmp/a.cpp
/tmp/a.cpp:4:1: warning: 'int main(int, const char**, const char**, const char**)' takes only zero or two arguments [-Wmain]
4 | main(int argc, const char **argv, const char **envp, const char **auxv)
| ^~~~
So much for backward compatibility and support for the original C++ operating
environment (unix).
Use getenv() - you don't need environment-variables you don't know.
scott@slp53.sl.home (Scott Lurndal) writes:
James Kuyper <jameskuyper@alumni.caltech.edu> writes:
On 2/2/25 13:05, Scott Lurndal wrote:
$ gcc --version
gcc (GCC) 14.2.1 20240912 (Red Hat 14.2.1-3)
$ g++ -O3 -o /tmp/a /tmp/a.cpp /tmp/a.cpp:4:1: warning: 'int main(int, >>>> const char**, const char**, const char**)' takes only zero or two
arguments [-Wmain]
4 | main(int argc, const char **argv, const char **envp, const char
**auxv)
| ^~~~
So much for backward compatibility and support for the original C++
operating
environment (unix).
Does it prevent the code from compiling and executing correctly in a
Unix environment? If not, it has no effect on the backwards
compatibility of the compiler.
Yes, if the programmer had used -Werror, as many do. This is
a recent change to g++.
That appears not to be the case. I see the same warning by default with >every version of g++ going back to 5.3.0, from 2015.
Am 03.02.2025 um 18:46 schrieb Scott Lurndal:
Use getenv() - you don't need environment-variables you don't know.
There are a number of use cases where your blanket statement is false.
extern char **environ;
Am 04.02.2025 um 15:30 schrieb Scott Lurndal:
So what? Every version of unix or unix-like operating
system has provided the environment vector as an
argument to main. They will continue to do that
ad infinitum.
environ is even portable across Windows.a
Am 04.02.2025 um 15:30 schrieb Scott Lurndal:
Bonita Montero <Bonita.Montero@gmail.com> writes:
Am 03.02.2025 um 18:46 schrieb Scott Lurndal:
Use getenv() - you don't need environment-variables you don't know.
There are a number of use cases where your blanket statement is false.
extern char **environ;
So what? Every version of unix or unix-like operating
system has provided the environment vector as an
argument to main. They will continue to do that
ad infinitum.
Polling is inacceptable.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 55:14:23 |
Calls: | 10,397 |
Calls today: | 5 |
Files: | 14,067 |
Messages: | 6,417,425 |
Posted today: | 1 |