Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!bbn!rochester!rutgers!sunybcs!bingvaxu!leah!uwmcsd1!uwmacc!hobbes!root From: root@hobbes.UUCP (John Plocher) Newsgroups: comp.lang.c Subject: Re: Accessing argc & argv from a functi Message-ID: <222@hobbes.UUCP> Date: Fri, 18-Sep-87 23:18:05 EDT Article-I.D.: hobbes.222 Posted: Fri Sep 18 23:18:05 1987 Date-Received: Sun, 20-Sep-87 11:23:41 EDT References: <22@flmis06.ATT.COM> <28700015@ccvaxa> <853@mcgill-vision.UUCP> <185@hobbes.UUCP> <884@mcgill-vision.UUCP> Reply-To: root@hobbes.UUCP (John Plocher) Followup-To: comp.lang.c Organization: U of Wisconsin - Madison Spanish Department Lines: 48 +---- der Mouse writes in <884@mcgill-vision.UUCP> ---- | [root@hobbes.UUCP (John Plocher) in <185@hobbes.UUCP>] ( me :-) | > int argc; char **argv; | > main(ac,av) { argc = ac; argv = av; .... } | > foo() { if (argc != 2) usage(); } | | > Why hardcode crt0? What does that buy you over this? | | It buys you the capability of writing a routine which accesses the | arguments without needing support from main(). Try explaining to your | beginning C programmer ... +---- Why not do something like I have done: In the public readable file /etc/default/c there exists a boilerplate C program which has the appropriate RCS header info, #include , getopt(), and argc/v/envp decls already there. Needless to say, it is heavily commented. The default .exrc for people has a macro which is attached to the ',' key which reads this file and then unmaps the ',' key... (there are also files for f77, make, header files, pascal...) and then let people know about their avaliability WHEN TEACHING the language! "To get you started programming C there is a sample C program avaliable which you should use to get started. Don't worry right now if you don't understand everything in the file, we will be covering all of the stuff in this course..." If they already know about argc/v then they SHOULD understand where they come from! If they don't know about it, why are they using the feature? I mean, if I tried to use Sys5's shared memory without knowing what I was doing I would run into problems too! Sometimes it is all right to learn from experience :-) Isn't the question really one of proper training? That is, where does one put the effort, education (argc/v) or handholding (library access). There are tradeoffs, but the first way is "portable" to other implementations of C while the second one is very site specific. If one wanted to make the arguments avaliable w/o going thru main() then I agree that you could just make crt0 put them into static locations, BUT would anyone use that feature? Would you? No, you (and I) know about argc/v and how to use them. The beginning C pgmr would soon learn the "right" way also, and use *it*. -- John Plocher uwvax!geowhiz!uwspan!plocher plocher%uwspan.UUCP@uwvax.CS.WISC.EDU