home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!cs.utexas.edu!uwm.edu!linac!unixhub!ditka!eagercon!eagercon!eager
- From: eager@eagercon.com (Michael J. Eager)
- Subject: Re: Problem with string processing.
- Message-ID: <1993Jan11.060615.2180@eagercon.com>
- Sender: root@eagercon.com (Operator)
- Reply-To: eager@eagercon.com
- Organization: Eager Consulting
- References: <1idn10INNpvg@calamari.hi.com>
- Date: Mon, 11 Jan 1993 06:06:15 GMT
- Lines: 29
-
- In article 1idn10INNpvg@calamari.hi.com, rogers@calamari.hi.com (Andrew Rogers) writes:
- >In article <Ts3TwB1w165w@wozzle.linet.org> alane@wozzle.linet.org (J. Alan Eldridge) writes:
- >>> char tmp[2] = {0};
- >>>
- >>> *tmp = ch;
- >>> strcat(str, tmp);
- >>
- >>tmp[0] has a 0 in it but tmp[1] is undefined. You are not creating
- >>a nul-terminated string here.
- >
- >tmp[1] most certainly does have a 0 in it; if the initialization list for
- >an array contains fewer elements than the array itself, then the remaining
- >array elements are initialized to 0. Check the ANSI spec, or the relevant
- >section in K&R.
-
- Well, the relevent section is 3.5.7, which says, in part "If an object that
- has automatic storage duration is not initialized explicitly, its value is
- indeterminate." Lacking a 'static' declaration and being within a function
- means that tmp has automatic storage. Only the first element is initialized
- to zero, tmp[1] is undefined.
-
- For static storage objects, all uninitialize elements get binary zero values.
-
-
- ---
- Michael J. Eager Michael.Eager@eagercon.com
- Eager Consulting (415) 325-8077
- 1960 Park Boulevard, Palo Alto, CA 94306-1141
-
-