From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f7344,2afd440a210c7fb0 X-Google-Attributes: gidf7344,public X-Google-Thread: 1014db,6bdc5c27a0dec527 X-Google-Attributes: gid1014db,public X-Google-Thread: 1164f8,df8a3dc583bf1f5f X-Google-Attributes: gid1164f8,public From: Dan.Pop@cern.ch (Dan Pop) Subject: Re: Compaq prefers Alpha over Merced! BUT OF COURSE, ALPHA * Date: 1998/09/07 Message-ID: X-Deja-AN: 388822389 References: <0095000017115526000002L062*@MHS> <6ss8cc$qrl@web.nmti.com> <6ssnp9$6pv$1@Starbase.NeoSoft.COM> <6svdad$ggd@web.nmti.com> <6t18af$p83$1@Starbase.NeoSoft.COM> X-Complaints-To: news@sunnews.cern.ch X-Trace: sunnews.cern.ch 905203656 8170 (None) 137.138.32.79 Organization: CERN European Lab for Particle Physics Newsgroups: comp.os.vms,comp.sys.dec,comp.lang.c In <6t18af$p83$1@Starbase.NeoSoft.COM> jordan@Starbase.NeoSoft.COM (Jordan Henderson) writes: >In article <6svdad$ggd@web.nmti.com>, >Peter da Silva wrote: >>In article <6ssnp9$6pv$1@Starbase.NeoSoft.COM>, >>Jordan Henderson wrote: >> >>> I think that, conceptually, the handling of command line arguments is >>> part of the core language. What >is< part of the core language and what is >>> not? And what is your justification for the separation? >> >>Basically, I think that the distinction between a hosted and embedded >>implementation is a good place to start. >> > >I still don't have the Standard document at hand, but does it clearly >say that non-hosted systems cannot have command line arguments? It just doesn't say anything about this issue WRT freestanding (non-hosted) environments. There is nothing in the standard preventing freestanding environments from providing access to command line arguments, if the very concept of "command line argument" has any meaning for that particular freestanding environment. But the mechanism used to pass them is not necessarily the same as in the case of a hosted environment (the arguments of main()). >I know that VRTX (and probably lots of other) real-time OS's allow you >to write programs that have command lines (they implement exec(), so >you have to have arguments). > >What exactly is the difference between hosted and non-hosted environments? I'll append the exact text from the standard. In a nutshell, a hosted environment benefits from the existence of an operating system, while a freestanding one doesn't. Think of a workstation versus a toaster. BTW, the operating system *itself* is running in a freestanding environment. To some operating systems you can pass command line arguments (e.g. this is how you boot most Unices in single user mode), to others you can't (e.g. CP/M, MS-DOS, Windows 95). >Even if command line arguments are not supported in non-hosted environments, >I have the string constants to fall back on for my claim that nul-terminated >strings are a "feature" of the language. Indeed, they are a feature of the language. Dan 2.1.2.1 Freestanding environment In a freestanding environment (in which C program execution may take place without any benefit of an operating system), the name and type of the function called at program startup are implementation-defined. There are otherwise no reserved external identifiers. Any library facilities available to a freestanding program are implementation-defined. The effect of program termination in a freestanding environment is implementation-defined. 2.1.2.2 Hosted environment A hosted environment need not be provided, but shall conform to the following specifications if present. "Program startup" The function called at program startup is named main . The implementation declares no prototype for this function. It can be defined with no parameters: int main(void) { /*...*/ } or with two parameters (referred to here as argc and argv , though any names may be used, as they are local to the function in which they are declared): int main(int argc, char *argv[]) { /*...*/ } If they are defined, the parameters to the main function shall obey the following constraints: * The value of argc shall be nonnegative. * argv[argc] shall be a null pointer. * If the value of argc is greater than zero, the array members argv[0] through argv[argc-1] inclusive shall contain pointers to strings, which are given implementation-defined values by the host environment prior to program startup. The intent is to supply to the program information determined prior to program startup from elsewhere in the hosted environment. If the host environment is not capable of supplying strings with letters in both upper-case and lower-case, the implementation shall ensure that the strings are received in lower-case. * If the value of argc is greater than zero, the string pointed to by argv[0] represents the program name ;argv[0][0] shall be the null character if the program name is not available from the host environment. If the value of argc is greater than one, the strings pointed to by argv[1] through argv[argc-1] represent the program parameters . * The parameters argc and argv and the strings pointed to by the argv array shall be modifiable by the program, and retain their last-stored values between program startup and program termination. "Program execution" In a hosted environment, a program may use all the functions, macros, type definitions, and objects described in the library section ($4). "Program termination" A return from the initial call to the main function is equivalent to calling the exit function with the value returned by the main function as its argument. If the main function executes a return that specifies no value, the termination status returned to the host environment is undefined. -- Dan Pop CERN, IT Division Email: Dan.Pop@cern.ch Mail: CERN - EP, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland