Re: declaration of variable in for loop
- From: Flash Gordon <spam@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 31 Jan 2008 18:26:45 +0000
santosh wrote, On 31/01/08 09:49:
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?
I'm assuming you misread Jacob's code as saying "pint=&k" which is what he intended (as noted in a subsequent post). If so then I would not expect a diagnostic although I would be pleased if the compiler produced one.
--
Flash Gordon
.
- References:
- declaration of variable in for loop
- From: poornimamprabhu
- Re: declaration of variable in for loop
- From: jacob navia
- Re: declaration of variable in for loop
- From: santosh
- declaration of variable in for loop
- Prev by Date: Re: Quick check on signed promotion of bytes
- Next by Date: Re: Quick check on signed promotion of bytes
- Previous by thread: Re: declaration of variable in for loop
- Next by thread: Re: declaration of variable in for loop
- Index(es):
Relevant Pages
|