- An interesting problem with accept()
- Posted by grocery_stocker on June 20th, 2008
On Jun 19, 6:36*pm, Barry Margolin <bar...@alum.mit.edu> wrote:
Why would not intializing client_addrlen matter? client_addrlen is
going to get the correct value when the function returns. If there is
a failure, wouldn't the error get copied over to client_addrlen and
hence overwrite the unitialized value of client_addrlen?
Chad
- Posted by Alex Fraser on June 20th, 2008
grocery_stocker wrote:
A value-result parameter means the value pointed to is used, as well as
(possibly) being updated by the function. In this particular case,
accept() will check the value pointed to is no smaller than the size of
the address, and fail if it isn't.
Alex
- Posted by Martijn Lievaart on June 20th, 2008
On Fri, 20 Jun 2008 12:51:34 -0700, grocery_stocker wrote:
Because the function wants to know if you allocated enough memory for the
value it wants to store. Otherwise it has to assume this and if you
didn't allocate enough memory, something will get corrupted.
M4
- Posted by grocery_stocker on June 21st, 2008
On Jun 20, 1:36*pm, Martijn Lievaart <m...@rtij.nl.invlalid> wrote:
I didn't know it was possible to allocate memory using something like
sizeof().
- Posted by santosh on June 21st, 2008
grocery_stocker wrote:
Sizeof is evaluated at compile time, so you can use it in allocating
dynamic memory (with malloc and friends) but you can't use it for
static allocations (though with C99 you can use it with Variable Length
Arrays.)
- Posted by Ben Bacarisse on June 21st, 2008
santosh <santosh.k83@gmail.com> writes:
I am not sure what you mean by "static allocation", but sizeof can be
used as part of an array size (with some restriction) in almost all
cases. You can certainly use it for automatic arrays, file-scope
arrays and arrays with the static storage class specifier.
To get a VLA from it you'd need to take the size of another VLA object
or include in the expression some term that is not a compile-time
constant.
--
Ben.