Topic: argc & argv in global constructors?


Author: chase@centerline.com (David Chase)
Date: 14 Nov 1994 14:47:13 GMT
Raw View

> B. Hurt <bhurt@blue.weeg.uiowa.edu> wrote:
> >In C the fact that you didn't have access to argc & argv before main()
> >didn't matter much, but now a program can execute significant and
> >non-trivial code before main is called- in global constructors.
> >Code whose behavior could depend upon command line parameters.

> >The changes to the language could be as minimal as including a new
> >header- say, argcv.h, whose behavior could be as simple as:
> >#ifndef ARGCV_H_INCLUDED
> >#define ARGCV_H_INCLUDED
> >   extern int argc;    // OS/Language guarentees these will be set
> >   extern char **argv; // before any code is exetecuted- even constructors!
> >#endif

> >All comments, information, etc. would be welcome...

Global data is vile.  I don't know how you want to spell it,
but the names "argc" and "argv" introduced by
ARGCV_H_INCLUDED should not necessarily be variables.
Perhaps I already have globals called "argc" and
"argv".  Presumably some macro wizard will know the
incantation that hits the right balance between namespace
pollution and usability, as in

#define argc __stdcpp_argc
#define argv __stdcpp_argv
extern int __stdcpp_argc;
extern char **__stdcpp_argv;

or perhaps defining them to be the result of a function
application (this is MUCH better, from the point of view
of retrofitting this into an existing implementation).

I think this is also a rather blunt instrument.  Perhaps
static and global objects should be considered an
unfortunate artifact of C++'s ancestry, and thus this
proposal should not fly? Consider all the headaches related
to order of static initialization, dynamically loaded code,
and now this.  Have we thought of the last headache caused
by the this language feature?  Might we not be better off
if this sort of coding were discouraged, rather than
encouraged?  (Yeah, I know, using global pointers to
explicitly allocated objects doesn't get you the same
syntactic goodies.  That, to me, is a real problem,
though I don't expect to see it fixed.)

David Chase, speaking for myself
CenterLine Software




Author: "Ronald F. Guilmette" <rfg@rahul.net>
Date: 15 Nov 1994 08:25:42 GMT
Raw View
In article <3a7t9h$9fn@wcap.centerline.com>,
David Chase <chase@centerline.com> wrote:
>
>
>> B. Hurt <bhurt@blue.weeg.uiowa.edu> wrote:
>> >In C the fact that you didn't have access to argc & argv before main()
>> >didn't matter much, but now a program can execute significant and
>> >non-trivial code before main is called- in global constructors.
>> >Code whose behavior could depend upon command line parameters.
>
>> >The changes to the language could be as minimal as including a new
>> >header- say, argcv.h, whose behavior could be as simple as:
>> >#ifndef ARGCV_H_INCLUDED
>> >#define ARGCV_H_INCLUDED
>> >   extern int argc;    // OS/Language guarentees these will be set
>> >   extern char **argv; // before any code is exetecuted- even constructors!
>> >#endif
>
>> >All comments, information, etc. would be welcome...
>
>Global data is vile.  I don't know how you want to spell it,
>but the names "argc" and "argv" introduced by
>ARGCV_H_INCLUDED should not necessarily be variables.

After agreeing with the earlier poster, I must now also agree 100% with
David Chase.  Global data objects cause major headaches in multi-threaded
programs.  You would not believe how many problems `errno' has caused in
such programs.

I guess what we really need is a pair of functions like:

 extern int argc_value (void);
 extern char **argv_value (void);

--

-- Ron Guilmette, Sunnyvale, CA ---------- RG Consulting -------------------
---- E-mail: rfg@segfault.us.com ----------- Purveyors of Compiler Test ----
-------------------------------------------- Suites and Bullet-Proof Shoes -




Author: girod@dshp01.trs.ntc.nokia.com (Marc Girod)
Date: 08 Nov 1994 08:45:41 GMT
Raw View
>>>>> "BH" == B Hurt <bhurt@blue.weeg.uiowa.edu> writes:
In article <398pu3$6cqn@blue.weeg.uiowa.edu> bhurt@blue.weeg.uiowa.edu (B. Hurt) writes:


BH> In C the fact that you didn't have access to argc & argv before main()
BH> didn't matter much, but now a program can execute significant and
BH> non-trivial code before main is called- in global constructors.
BH> Code whose behavior could depend upon command line parameters.

BH> The changes to the language could be as minimal as including a new
BH> header- say, argcv.h, whose behavior could be as simple as:
BH> #ifndef ARGCV_H_INCLUDED
BH> #define ARGCV_H_INCLUDED
BH>    extern int argc;    // OS/Language guarentees these will be set
BH>    extern char **argv; // before any code is exetecuted- even constructors!
BH> #endif

BH> All comments, information, etc. would be welcome...

I agree with you. This is already available according to my man page
for crt0:

--------------------------------
DESCRIPTION
     The C and Pascal compilers link in files crt0.o, gcrt0.o, or mcrt0.o
     to provide startup capabilities and environment for program execution.
     All are identical except that gcrt0.o and mcrt0.o provide additional
     functionality for gprof(1) and prof(1) profiling support respectively.
     Similarly, the FORTRAN compiler links in either frt0.o, gfrt0.o, or
     mfrt0.o.

     The following symbols are defined in these routines:

          __argc_value        A variable of type int containing the number
                              of arguments.

          __argv_value        An array of character pointers to the
                              arguments themselves.

[...]

AUTHOR
     The features described in this entry originated from AT&T UNIX System
     III.

--------------------------------

I was told that the portability clause is not broad enough, but I
guess compatibility with this should be kept.

Regards
--
+-----------------------------------------------------------------------------+
| Marc Girod - Nokia Telecommunications       Phone: +358-0-511 7703          |
| TL4E - P.O. Box 12                            Fax: +358-0-511 7432          |
| SF-02611 Espoo 61 - Finland              Internet: marc.girod@ntc.nokia.com |
|    X.400: C=FI, A=Elisa, P=Nokia Telecom, UNIT=TRS, SUR=Girod, GIV=Marc     |
+-----------------------------------------------------------------------------+




Author: rtf@cadre.com (Read Fleming)
Date: Tue, 8 Nov 1994 16:31:46 GMT
Raw View
girod@dshp01.trs.ntc.nokia.com (Marc Girod) writes:

> I agree with you. This is already available according to my man page
> for crt0:
>
>  (HP man page describing, among other things, globals __argc_value and
    __argv_value snipped)
>
> I was told that the portability clause is not broad enough, but I
> guess compatibility with this should be kept.
                           ^^^^

I like the idea of exporting arg and argv.  But be careful about extrapolating
from one comany's *implementation* (note the leading "__" in the names).  Check
the documentation for other platforms before gauging "current practice."






Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Tue, 8 Nov 1994 16:50:37 GMT
Raw View
In article <39i0np$2tu@hustle.rahul.net> "Ronald F. Guilmette" <rfg@rahul.net> writes:
>In article <398pu3$6cqn@blue.weeg.uiowa.edu>,
>B. Hurt <bhurt@blue.weeg.uiowa.edu> wrote:
>>In C the fact that you didn't have access to argc & argv before main()
>>didn't matter much, but now a program can execute significant and
>>non-trivial code before main is called- in global constructors.
>>Code whose behavior could depend upon command line parameters.
>>
>>The changes to the language could be as minimal as including a new
>>header- say, argcv.h, whose behavior could be as simple as:
>>#ifndef ARGCV_H_INCLUDED
>>#define ARGCV_H_INCLUDED
>>   extern int argc;    // OS/Language guarentees these will be set
>>   extern char **argv; // before any code is exetecuted- even constructors!
>>#endif
>>
>>All comments, information, etc. would be welcome...
>
>I endorse your suggestion wholeheartedly.

 While I'd prefer to remove any such requirements
along with cin, cout, cerr, stdin, stderr, and stdout because
these entities belong in a POSIX binding of the language
and not the architecture and operating system independent
core language. The language assumes a file system,
it should NOT assume a brain dead character mode teletype
in this day and age.  (They went out of date 20 years ago)

 I recommend you hassle your _implementor_ who
is free to supply non-standard extensions to grant access to
the command line prior to main() being called.
--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
 Maxtal Pty Ltd,
        81A Glebe Point Rd, GLEBE   Mem: SA IT/9/22,SC22/WG21
        NSW 2037, AUSTRALIA     Phone: 61-2-566-2189




Author: bhurt@blue.weeg.uiowa.edu (B. Hurt)
Date: 2 Nov 1994 13:39:47 -0600
Raw View
In C the fact that you didn't have access to argc & argv before main()
didn't matter much, but now a program can execute significant and
non-trivial code before main is called- in global constructors.
Code whose behavior could depend upon command line parameters.

The changes to the language could be as minimal as including a new
header- say, argcv.h, whose behavior could be as simple as:
#ifndef ARGCV_H_INCLUDED
#define ARGCV_H_INCLUDED
   extern int argc;    // OS/Language guarentees these will be set
   extern char **argv; // before any code is exetecuted- even constructors!
#endif

All comments, information, etc. would be welcome...

My .sig is on strike.




Author: "Ronald F. Guilmette" <rfg@rahul.net>
Date: 6 Nov 1994 07:31:05 GMT
Raw View
In article <398pu3$6cqn@blue.weeg.uiowa.edu>,
B. Hurt <bhurt@blue.weeg.uiowa.edu> wrote:
>In C the fact that you didn't have access to argc & argv before main()
>didn't matter much, but now a program can execute significant and
>non-trivial code before main is called- in global constructors.
>Code whose behavior could depend upon command line parameters.
>
>The changes to the language could be as minimal as including a new
>header- say, argcv.h, whose behavior could be as simple as:
>#ifndef ARGCV_H_INCLUDED
>#define ARGCV_H_INCLUDED
>   extern int argc;    // OS/Language guarentees these will be set
>   extern char **argv; // before any code is exetecuted- even constructors!
>#endif
>
>All comments, information, etc. would be welcome...

I endorse your suggestion wholeheartedly.
--

-- Ron Guilmette, Sunnyvale, CA ---------- RG Consulting -------------------
---- E-mail: rfg@segfault.us.com ----------- Purveyors of Compiler Test ----
-------------------------------------------- Suites and Bullet-Proof Shoes -