Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

on main

53 views
Skip to first unread message

asetof...@gmail.com

unread,
Apr 9, 2015, 8:13:04 AM4/9/15
to
I would like to know if
main(x){printf("%x",x);}
Is a valid C++ program
and what number it print...

Victor Bazarov

unread,
Apr 9, 2015, 9:06:42 AM4/9/15
to
Not a valid C++ program.

V
--
I do not respond to top-posted replies, please don't ask

Juha Nieminen

unread,
Apr 9, 2015, 11:58:56 AM4/9/15
to
asetof...@gmail.com wrote:
> main(x){printf("%x",x);}

It might have been valid very ancient C (although I don't think it's
valid by any *standardization*, but many C compilers will accept it).

--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---

asetof...@gmail.com

unread,
Apr 9, 2015, 12:00:56 PM4/9/15
to
main(x){printf("%x",x);}
Seems to me here would print 1

Robert Wessel

unread,
Apr 9, 2015, 4:44:20 PM4/9/15
to
On Thu, 9 Apr 2015 09:00:46 -0700 (PDT), asetof...@gmail.com
wrote:

>main(x){printf("%x",x);}
>Seems to me here would print 1


Even if this worked as (apparently) expected, the number printed would
depend on how the program was invoked.

Vir Campestris

unread,
Apr 9, 2015, 4:54:15 PM4/9/15
to
On 09/04/2015 14:06, Victor Bazarov wrote:
> On 4/9/2015 8:12 AM, asetof...@gmail.com wrote:
>> I would like to know if
>> main(x){printf("%x",x);}
>> Is a valid C++ program
>> and what number it print...
>
> Not a valid C++ program.
>
Not valid - or just not compatible with any OS I ever came across?

(Win and *n?x seem to require argc and argv...)

Andy

Geoff

unread,
Apr 9, 2015, 5:22:50 PM4/9/15
to
On Thu, 9 Apr 2015 09:00:46 -0700 (PDT), asetof...@gmail.com
wrote:

>main(x){printf("%x",x);}
>Seems to me here would print 1

Why?

Martin Shobe

unread,
Apr 9, 2015, 7:38:00 PM4/9/15
to
Not valid. There are several things, including a type for x and a
prototype for printf, that need to be fixed before we talk about the
non-standard prototype for main.

Martin Shobe

Lőrinczy Zsigmond

unread,
Apr 10, 2015, 12:30:08 AM4/10/15
to

Scott Lurndal

unread,
Apr 10, 2015, 9:50:28 AM4/10/15
to
*n?x provides argc, argv, envp and auxv. Most programs
only use argc, argv, and some use envp as well. There is
nothing illegal or undefined about defining main to consume
only the argc parameter; the remaining parameters passed by
the exec call will be ignored and unavailable to the app
(although getenv()/setenv()/putenv() will access the environment
directly). auxv, which is passed from the kernel,
is often consumed by the run-time-linker/loader and may or may
not be provided to the application depending on the OS.

As otherwise pointed out, the value of the 'argc' parameter
depends on how the main function was invoked.

scott

Robert Wessel

unread,
Apr 10, 2015, 2:34:36 PM4/10/15
to
On Fri, 10 Apr 2015 13:50:18 GMT, sc...@slp53.sl.home (Scott Lurndal)
wrote:

>Vir Campestris <vir.cam...@invalid.invalid> writes:
>>On 09/04/2015 14:06, Victor Bazarov wrote:
>>> On 4/9/2015 8:12 AM, asetof...@gmail.com wrote:
>>>> I would like to know if
>>>> main(x){printf("%x",x);}
>>>> Is a valid C++ program
>>>> and what number it print...
>>>
>>> Not a valid C++ program.
>>>
>>Not valid - or just not compatible with any OS I ever came across?
>>
>>(Win and *n?x seem to require argc and argv...)
>>
>
> *n?x provides argc, argv, envp and auxv. Most programs
>only use argc, argv, and some use envp as well. There is
>nothing illegal or undefined about defining main to consume
>only the argc parameter; the remaining parameters passed by
>the exec call will be ignored and unavailable to the app
>(although getenv()/setenv()/putenv() will access the environment
>directly). auxv, which is passed from the kernel,
>is often consumed by the run-time-linker/loader and may or may
>not be provided to the application depending on the OS.


There's' nothing preventing an implementation from providing an
extension so that a form of main() other than the two specified in the
standard are supported, but the form being proposed here is undefined
per the standard. Yes, with some of the common calling conventions
used by C implementations it would work naturally, but that is
certainly not required.
0 new messages