Author of the article here. There's no intention here to encourage people to use this in code (in fact the opposite). This article is more of a "Did you know cool shit like this exist?".
How to find size of an array in C without sizeof
181–190 of 212 posts
Re: How to find size of an array in C without sizeof
#182Earlier quoted context omitted.
I don't think that's universally true, some languages are quite sound and logical at their core.
Name a language and someone will point out WTFs and subtle issues you might have never considered. The problem is the same when designing a language: computers think best with a large set of simple rules, humans think best with a small set of complicated rules, each having exceptions and different tiers of complexity for different levels of each developer's understanding. I find C somewhat logical, but it has an easy…
C evolved in a different age and is fraught with undefined behavior.
Re: How to find size of an array in C without sizeof
#183Earlier quoted context omitted.
Is there a circle in hell reserved for C standards committee members who add to the number of cases where 'undefined behavior' occurs in the standards?
Just how would you make this case defined ? The alternatives to undefined behavior tend to be (1) being silent about the issue and letting users and implementers find out themselves (2) defining the behavior in a way that makes it difficult to implement on some architectures or (3) defining the behavior in a way that imposes costs on all architectures. None of these is particularly attractive.
Re: How to find size of an array in C without sizeof
#184Earlier quoted context omitted.
In many more theoretical CS classes, programming is not a requirement.
There's a word for that. It's "math".
Re: How to find size of an array in C without sizeof
#185Earlier quoted context omitted.
I'll appreciate if you could provide a screenshot :)
(1)- Taken using chrome extension: http://imgur.com/a/PYMRD (2)- Print screen of chrome version 54.0.2840: http://imgur.com/a/dDwK9 (3)- Print screen of internet explorer version 11 : http://imgur.com/a/uxAv5 All running on 32bit windows 8.1
Re: How to find size of an array in C without sizeof
#186Author of the article here. There's no intention here to encourage people to use this in code (in fact the opposite). This article is more of a "Did you know cool shit like this exist?".
Please fix your site's header :)
Re: How to find size of an array in C without sizeof
#187Earlier quoted context omitted.
(1)- Taken using chrome extension: http://imgur.com/a/PYMRD (2)- Print screen of chrome version 54.0.2840: http://imgur.com/a/dDwK9 (3)- Print screen of internet explorer version 11 : http://imgur.com/a/uxAv5 All running on 32bit windows 8.1
Author might have fixed it already, but it looks alright to me on Chrome 55.0.2883.95 / macOS 10.12. http://imgur.com/a/fhDr1
Re: How to find size of an array in C without sizeof
#188Earlier quoted context omitted.
Technically, this needn't impact malloc, because dereferencing the "one past the end" address is still undefined. All you need is logic in your pointer arithmetic that essentially treats the past the end address as a special value (which normally would never need to be represented).
Not just pointer arithmetic; also pointer comparisons. One-past-the-end pointer must compare greater-than any other pointer into that array. So an implementation that could stick an array at the very end of the address space, and do wraparound for one-past-the-end so that it's represented by all bits zero, would then need to special-case that zero value when performing any pointer comparisons.
But yes, you'd need logic for pointer comparisons as well.
Re: How to find size of an array in C without sizeof
#189Earlier quoted context omitted.
The problem you're latching on to I think is how the context for caculating a probability can vary. If it were really as likely as, say, the sun exploding that X happened then it would be of no use to expend time on X. BUT very often people speaking about the probability of events given suspicious constraints. While a memory allocation might not fail in most situations it will fail often in some situations. And a one…
That's why it's called one in a million...
Re: How to find size of an array in C without sizeof
#190Earlier quoted context omitted.
That's why it's called one in a million...
One in a million isn't just a typical statement of probability, it's a colloquialism used to refer to things that never happen in practice. It's highly misleading to use in the context of computers which, due to their natures, have one in a million events occurring constantly.