sorry i remember things after i post
note these
1.cpp:18: warning: unused variable `char buf[((i - 1) + 1)]
^^^^^^^^^^^^^^^
--- In [email protected], "Indika Bandara" <[EMAIL PROTECTED]>
wrote:
>
> compiled with gcc/linux
> no errors/warnings
>
> int main()
> {
> int i=5;
> char buf[i];
> return 0;
> }
>
> is the compiler so smart that he checks i doesn't get changed and
> accepts above??
>
> interestingly, it says this when given -Wall
>
> 1.cpp: In function `int main()':
> 1.cpp:18: warning: unused variable `char buf[((i - 1) + 1)]'
>
>
>
>
> --- In [email protected], Ray Devore <rbdevore2007@> wrote:
> >
> > --- Indika Bandara <indikabandara19@> wrote:
> > > is this ok? this works sometimes
> > >
> > > 1)
> > > func(int i)
> > > {
> > > char buf[i];
> > > // access buf until i
> > >
> > > }
> > > usage:
> > > func(5);
> > >
> > >
> > > 2)
> > > func()
> > > {
> > > int i = 5;
> > > char buf[i];
> > > // access buf until i
> > >
> > > }
> > >
> > >
> > > will these not produce segfaults? then why?
> > >
> > >
> > I don't see why they are not giving you compile errors
> > since the size of an array is supposed to be a const
> > or a literal, not a variable.
> >
> > When you say "until i" can you provide the code you
> > are using for the loop? If you are using the value at
> > buf[i] then you should be a segfault sometimes. It
> > depends on whether you have control of that address or
> > some other program does.
> >
> > Need more information.
> >
> > Ray
> >
> >
> >
> >
>
____________________________________________________________________________________Be
> a better Heartthrob. Get better relationship answers from someone who
> knows. Yahoo! Answers - Check it out.
> > http://answers.yahoo.com/dir/?link=list&sid=396545433
> >
>