Re: Program crashes when running it outside dev environment



Harald van =?UTF-8?B?RMSzaw==?= wrote:

Richard Heathfield wrote:


But I don't know
of any occasion where you *need* a cast AND omitting it violates a
constraint or constitutes a syntax error.

I can't think of a concrete example of a cast which
causes a constraint
violation or syntax error when left out either, but diagnostics are
permitted for other code as well.

You need a cast if you're writing a function like strchr, strstr
or bsearch, which returns a pointer to an unqualified type,
which is derived from a parameter that points to a qualified type.

char *strstr(const char *s1, const char *s2)
{
const int c = *s2++;

if (c != '\0') {
const size_t n = strlen(s2);

s1 = strchr(s1, c);
while (s1 != NULL && strncmp(s1 + 1, s2, n) != 0) {
s1 = strchr(s1 + 1, c);
}
}
return (char *)s1;
}


--
pete
.



Relevant Pages

  • Re: Program crashes when running it outside dev environment
    ... of any occasion where you *need* a cast AND omitting it violates a ... constraint or constitutes a syntax error. ... You need a cast if you're writing a function like strchr, ...
    (comp.lang.c)
  • Re: herding ones and zeroes into bytes
    ... int main ... char pattern; ... (Missing operator before byte?) ... syntax error at sln1.pl line 27, ...
    (comp.lang.perl.misc)
  • Re: IEeeeee Help!
    ... Try an Exchange newsgroup. ... E.g. one case that I have noticed is that if the HTML DOCTYPE ... specification isn't on line 1 IE detects a syntax error. ... > Char: 1 ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: IEeeeee Help!
    ... Try an Exchange newsgroup. ... E.g. one case that I have noticed is that if the HTML DOCTYPE ... specification isn't on line 1 IE detects a syntax error. ... > Char: 1 ...
    (microsoft.public.exchange.clients)
  • Re: resolving types
    ... unsigned char ... are the result of your first error: using the unknown type 'bool', after which your compiler is going nuts trying to make sense of what follows. ... C2061: syntax error: identifier 'WriteLog' ...
    (comp.lang.c)