Re: declaration of variable in for loop



jacob navia wrote:

<snip>

main()
{
int i,j, *pint;
for(i=0;i<10;i++){
int k = i;
printf("%d %p = *%d\n",i,&k,k);
pint=&i;
}
*pint = 789; // Accessing illegal storage
}

This would work on lcc-win since the storage is still valid.
I would not do this since it is absolutely non portable.
Other compilers could implement other strategies.

I hope as a QoI issue lcc-win issues a diagnostic for such uses?

<snip>

.



Relevant Pages

  • Re: declaration of variable in for loop
    ... int i,j, *pint; ... This would work on lcc-win since the storage is still valid. ... Other compilers could implement other strategies. ...
    (comp.lang.c)
  • Re: Haldanes Dilemma - clarifications - and Felsenstein [LONG]
    ... This sounds like a consequence of the theory of 'nearly neutral' selection. ... We take two at random, and return the one with the highest fitness, ... int choose ...
    (sci.bio.evolution)
  • Re: c interview
    ... undefined behaviour because printf is a varidac function. ... stdio.h before using printf and other headers as appropriate before ... Would make it a point that the size of int is assumption to be .... ...
    (comp.lang.c)
  • Re: || putchar(ch == 177 ? ? : ch | 0100) == EOF)
    ... snip 160 lines of obsolete commentary ... void filecopy(FILE *ifp, FILE *ofp) ... int ch; ... Since you expect the file to contain control character, ...
    (comp.lang.c)
  • Re: for loop problem
    ... int flushln{ ... gcc chokes big-time on this until I add #include, ... snip about 150 lines of spouting ... ... I don't recall requesting that 150 odd lines of spouting about your ...
    (comp.lang.c)