G
Guest
(stderr), (stdin), and (stdout)
are three examples of lowercase macros.
since when have these been macros?
(stderr), (stdin), and (stdout)
are three examples of lowercase macros.
[...]I don't think _Exit() is standard (unless it's in a newer standard
than I'm familiar with)
since when have these been macros?
Secondly, your characterisation of the size is, err... provocative.
All arrays (malloced or otherwise) are of bounded size so (i) is a red
herring.
What you mean is that VLAs have no portably guaranteed failure
mechanism. On a particular implementation they may very well
have a well-defined, implementation-supplied, such mechanism.
Secondly, your characterisation of the size is, err... provocative.
No. I mean "trivially small" in the sense that "it really doesn't
matter how many of these you have, something else will blow up first,
so don't worry about it."
All arrays (malloced or otherwise) are of bounded size so (i) is a red
herring.
They're not bounded at compile time, or at the time you set the stack-
size. Arrays are often dependent on the input size, and often non-
linearly so (say calculating a Gram matrix). If you don't know the
input size in advance, and it might be large, VLAs are a non-starter.
Again, VLAs are fine if and only if,
i) if you, or your library user, knows the maximum input size in
advance,
ii) you're happy doing the worst-case stack calculation by hand and
setting a sufficient stacksize [or, better, leave this to your users!]
(good luck if you're doing an adaptive / multiscale grid solver)
iii) you don't mind undefined behaviour if someone get that
calculation wrong...
Conclusion:
Be careful with the stack.
this isn't a universal convention- though it's a common one
בת×ריך ×™×•× ×©× ×™, 25 ×‘×™×•× ×™ 2012 22:27:02 UTC+1, מ×ת Tim Rentsch:
And these days if you're writing C you're probably more likely to be writing components rather than complete programs. A component does know what todo on out of memory -sometimes relying on the OS to kill the process is the best you can do, sometimes its completely unacceptable.
David said:I agree - that's why I am suggesting the OP looks at alternatives that
might be a better choice overall, rather than following the "only C is
fast enough" fanboyism.
Le 26/06/12 11:38, gwowen a écrit :Secondly, your characterisation of the size is, err... provocative.
No. I mean "trivially small" in the sense that "it really doesn't
matter how many of these you have, something else will blow up first,
so don't worry about it."
All arrays (malloced or otherwise) are of bounded size so (i) is a red
herring.
They're not bounded at compile time, or at the time you set the stack-
size. Arrays are often dependent on the input size, and often non-
linearly so (say calculating a Gram matrix). If you don't know the
input size in advance, and it might be large, VLAs are a non-starter.
Again, VLAs are fine if and only if,
i) if you, or your library user, knows the maximum input size in
advance,
ii) you're happy doing the worst-case stack calculation by hand and
setting a sufficient stacksize [or, better, leave this to your users!]
(good luck if you're doing an adaptive / multiscale grid solver)
iii) you don't mind undefined behaviour if someone get that
calculation wrong...
Look, when you do:
int fn(void)
{
double table[4096];
}
There is no failure indication if there wasn't any more stack space for
allocating 4096 doubles.
VLA's are the same.
Conclusion:
Be careful with the stack.
gwowen said:Well, yes. But you could say the same for NULL pointer dereferences.
Malcolm McLean said:Tim Rentsch:
And these days if you're writing C you're probably more likely to be
writing components rather than complete programs. A component does
know what to do on out of memory -sometimes relying on the OS to
kill the process is the best you can do, sometimes its completely
unacceptable.
Tim Rentsch said:not?
as using malloc() is no different in this regard.
gwowen said:Well, yes. But you could say the same for NULL pointer dereferences.
The only difference is that implentations that give predictable
behaviour for NULL pointer dereferences actually exist, as opposed to
being completely theoretical.
One can always guard: >>if(p)*p;<<, I am not aware of the corresponding
guard for VLAs.
When a library-grade function needs to allocate memory
and this fails, it knows what to do: Notify the caller
of the failure (usually via a status code).
gwowen said:No. I mean "trivially small" in the sense that "it really doesn't
matter how many of these you have, something else will blow up first,
so don't worry about it."
They're not bounded at compile time, or at the time you set the stack-
size. Arrays are often dependent on the input size, and often non-
linearly so (say calculating a Gram matrix). If you don't know the
input size in advance, and it might be large, VLAs are a non-starter.
Again, VLAs are fine if and only if,
i) if you, or your library user, knows the maximum input size in
advance,
ii) you're happy doing the worst-case stack calculation by hand and
setting a sufficient stacksize [or, better, leave this to your users!]
(good luck if you're doing an adaptive / multiscale grid solver)
iii) you don't mind undefined behaviour if someone get that
calculation wrong...
gwowen said:No. I mean "trivially small" in the sense that "it really doesn't
matter how many of these you have, something else will blow up first,
so don't worry about it."
I don't know what this means. Sounds like more polemic, but maybe there
is a significant point here.
They're not bounded at compile time, or at the time you set the stack-
size. Arrays are often dependent on the input size, and often non-
linearly so (say calculating a Gram matrix). If you don't know the
input size in advance, and it might be large, VLAs are a non-starter.
So by "not bounded" you meant that the size is not known at compile
time. That's the essence of VLAs. This criticism is that VLAs are
a non-starter because they are VLAs.
Again, VLAs are fine if and only if,
i) if you, or your library user, knows the maximum input size in
advance,
ii) you're happy doing the worst-case stack calculation by hand and
setting a sufficient stacksize [or, better, leave this to your users!]
(good luck if you're doing an adaptive / multiscale grid solver)
Straw man. Who said anything about doing an adaptive / multiscale grid
solver with stack-allocated VLAs?
iii) you don't mind undefined behaviour if someone get that
calculation wrong...
Do you do ii) and accept iii) for all your programs, because they apply
in the absence of VLAs? I don't. Most of the time I just assume that I
don't run out of stack and that if I do my system will let me know.
There are cases when the same rough and ready approach works with VLAs.
Well, that was sort of my original point.
I am not a standardisation document.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.