Follow Slashdot blog updates by subscribing to our blog RSS feed

 



Forgot your password?
typodupeerror
×

Comment Re:Ugh. (Score 2) 159

I'm not too sure about the realloc example. The man page on my Mac says

If size is zero and ptr is not NULL, a new, minimum sized object is allocated and the original object is freed.

That says to me its behaviour is already aligned with the new standard and I'm not sure if it ever wasn't.

Furthermore, I don't think I've ever seen C code that uses the behaviour described by the article. The example of grep doesn't use it, it only uses the "passing in a null pointer is the same as malloc" behaviour. Also, the example stack is a bit bogus. A real implementation would never bother to realloc with less memory because you're almost certainly going to need to grow the stack again at some future time.

Comment Re:Comparing unrelated pointers (Score 1) 159

That's just a subset of undefined behaviour and it limits what an implementation can do. For example, the designers of a C compiler for a segmented architecture may want to trap if you try to compare two pointers in different segments but give a sane answer if you compare two pointers in the same segment.

"Undefined behaviour" means "the implementor can do whatever is convenient" and for implementors targeting a flat address space, it's convenient to return a sane value no matter where the two pointers came from. It means, for example, they can implement memmove() without copying the source block into a temporary array (to avoid corruption id the source and destination overlap).

Slashdot Top Deals

Kleeneness is next to Godelness.

Working...