13 ms·
I'm surprised at all of the comments calling this stupid or pointless. The point is not that you should this trick in lieu of sizeof; the point is to shed light
by millstone 10y ago
I'm surprised at all of the comments calling this stupid or pointless. The point is not that you should this trick in lieu of sizeof; the point is to shed light on a subtly of C arrays.
- btrask 10y agoI suspect this article made a lot of people feel stupid, or in other words, it taught us something. Sometimes the ego gets out of check. I think the article is well-presented and educational.
- grobbles 10y agoI suspect this article made a lot of people feel stupid Anyone who doesn't understand pointer arithmetic in C has no business being involved with C. I'm not trying to be negative about this post, but the notion that people are feeling "stupid" about this is hysterical. HN has absolutely trended toward utterly beginner type C information being some novelty on here. It's a bit bizarre, and the general skill level of the site has catastrophically declined.
- gragas 10y ago>I think this article made a lot of people feel stupid I don't think so. Anyone with a solid understanding of C understands pointer arithmetic. I think the article isn't obvious only to those who have a weak understanding of the language.
- jmspring 10y agoThere are many that have a weak understanding of the language. I got asked some years back why I defaulted to C in some interview questions -- I grew up with the language, understand the nuances and many of the implementations. It's now possible to make your way through a university education in CS without ever touching or understanding C. This is a problem.
- gragas 10y ago>It's now possible to make your way through a university education in CS without ever touching or understanding C. This is a problem. I suppose that this is the case. But really, to me this is article does not reveal anything beyond what I already knew from basic pointer arithmetic.
- vostok 10y ago> It's now possible to make your way through a university education in CS without ever touching or understanding C. This is a problem. I did not study CS, but I had a number of CS modules/classes. LaTeX was the only programming language I recall using. Students with better handwriting could probably get away with not doing any programming at all. It's not clear to me that this is a problem, but I imagine that the systems requirement of most CS programs will involve C. For what it's worth, I default to python in interviews even though it's my least favorite out of the languages that I use frequently.
- ageofwant 10y ago> I default to python in interviews even though it's my least favorite out of the languages that I use frequently. Why is that ? I would image that you'd use the language you are most comfortable with and trust the most during an interview ? What makes Python a good 'interview' language but a less good bread and butter language for you ?
- jonathankoren 10y agoIf he's listing LaTeX as a programming language and talking about how little programming he had, I suspect he's stuck with R or Matlab.
- spicyj 10y agoTeX is a "real" programming language.
- 10y ago
- logicallee 10y ago>I think the article isn't obvious only to those who have a weak understanding of the language. Hi! Could you take a guess at what percentage of C programmers who write C professionally fit your definition of that (I realize you were being hasty in your phrasing, but still)? Obviously your answer should be betweeen 0% (no programmer who writes C professionally) and 100% (every programmer who writes C professionally.) I'm genuinely curious what you think! Thanks :)
- gragas 10y agoI think less than 15% of professional C programmers have a weak understanding of the language. One only needs a basic understanding of pointer arithmetic to understand why `(&arr + 1) - arr` is the size of the array.
- logicallee 10y agoso you think 85% of programmers who write C can parse (&arr + 1) - arr to find the size of the array, without the use of the article? This is surprisingly high and I am pretty sure at least the majority of people who get paid to write C would fail that. Not because it's not the case that they "should" know it, but simply because it's possible to write C without knowing it, and some people do so. For example consider embedded programmers who might not be specialists at all. I very much doubt that 85% of C programmers know these things. It would be interesting to find out!
- psyc 10y agoI can only speak for myself. I wrote C code for many years, a long time ago. I'm 100% certain that I never had occasion to use a "pointer to array" type. If you asked me a series of leading questions, like "Can you have a pointer to array of 10 ints?" and "What would happen if you increment that?" I would probably get the right answer, with low confidence. There's almost no way I would have thought of this way of getting the array size without reading something like this article. And what's wrong with learning something from an article? This is really not about pointer arithmetic at all. Rather it's about a particular use of C's near-infinitely composable type system.
- anigbrowl 10y agoQuite. This exactly the sort of thing that makes C such a fun language.
- shmerl 10y agoI'm not sure if it's a praise for C though. Arcane design and lack of clarity might be fun to decipher, but it's not something that you'd want to see in the programming language.
- droopyEyelids 10y agoDoesn't every language turns into insanity to decipher once you look close enough?
- pg_is_a_butt 10y agoyes. what does "turns into" mean? did you mean "turn into"? you are insane.
- pshc 10y agoI don't think that's universally true, some languages are quite sound and logical at their core.
- vortico 10y agoName 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-to-learn simplified version of itself that can be learned before re-reading the spec to complete your understanding of the language.
- shmerl 10y ago
- pwython 10y agoYou've been on here 4 years and are surprised at the top comments criticizing the content of a post? :) There's a reason this meme exists: http://i.imgur.com/Z6pFTjj.jpg http://i.imgur.com/Z6pFTjj.jpg
- jheriko 10y agopersonally the issue i take with this article is that it displays an opinion that is counterproductive to learning (imo). rather than calling out that pointer arithmetic implicitly relies on 'sizeof' in order to be useful, its treated like some kind of magic. i.e. i don't think it points out the not subtle but rather obvious connection, and instead distracts from it...
- JBiserkov 10y agoYour comment: >rather than calling out that pointer arithmetic implicitly relies on 'sizeof' Article: >arr has the type int , where as &arr has the type int ()[size]. For me this is calling out the implicit use of sizeof by pointing out the type.