This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Is this code valid under g++
- From: LLeweLLyn Reese <llewelly at lifesupport dot shutdown dot com>
- To: "Ajay Bansal" <Ajay_Bansal at infosys dot com>
- Cc: <gcc-help at gcc dot gnu dot org>
- Date: 20 Mar 2003 10:50:17 -0800
- Subject: Re: Is this code valid under g++
- References: <2B721C6525F0D411B1E900B0D0226BDD02149290@mohmsg01.ad.infosys.com>
- Reply-to: gcc-help at gcc dot gnu dot org
"Ajay Bansal" <Ajay_Bansal at infosys dot com> writes:
> Is the following code corect??
>
>
> char*
> getNextItem(char* line, const char* delimit)
> {
> // Retrieve the next item, and strip off any whitespace around it
> char* item;
> char* tmp;
>
> item = strtok(line, delimit);
> if (item)
> {
> // Strip off leading whitespace
> while (*item == ' ' || *item == ' ')
No. ' ' is a multicharacter char literal. It is not part of standard
C++, not portable in general, and AFAIK a gcc extension. If you
mean a tab, use \t.
> {
> item++;
> } // while
>
> // Find any trailing spaces, tabs, newlines
> tmp = strpbrk(item, " \t\n");
> if (tmp)
> {
>
> *tmp = '\0';
> } // if
>
> // Comment, or end of line
> if (*item == '#' || *item == '\n' || *item == '\0')
> {
> // Return as if nothing
> item = 0;
> } // if
> } // if
>
> return item;
> } // getNextItem()
>
>
> CAN WE RETURN item
Yes.
> (it is local to the function)
No.
*item is not local to the function. Upon return, item is either null,
or points into the char array pointed to by line.