News for hackers. Stuff that matters.
Re:Massacring C Pointers (2018) by tom_mellior on Saturday September 05, 2020 @12:15PM (#24384656)
This is true, as long as your definition of "another variable" stretches far enough to include memory regions allocated by malloc. And (leaving the C standard), also things allocated through other means, like memory-mapped files, and things like like memory-mapped peripherals.

In other words, the statement is incorrect.

Re:Massacring C Pointers (2018) by saagarjha on Saturday September 05, 2020 @12:46PM (#24384925)
I was specifically responding to the comment above, which had clearly conflated the standard not specifying the representation of a pointer with “anything anyone says about pointers isn’t actually correct”. Keeping the standard in mind the definition of “variable” generally extends to “any typed memory regardless of whether it has a name or not”, and the pointers K&R are talking about are fairly clear to mean this in the sense of the pointer being dereferenceable to a specific type. That being said, you are correct that there are other pointers not mentioned in that statement that are an entirely separate class from normal data pointers: untyped buffers, usually specified by void * but (for legacy reasons) often char * as well. And of course, there’s also function pointers that you dereference only to call them.
Re:Massacring C Pointers (2018) by grayhatter on Saturday September 05, 2020 @12:38PM (#24384861)
Um, why wouldn't it be correct to call any/all of thoes examples a variable?
Re:Massacring C Pointers (2018) by saagarjha on Saturday September 05, 2020 @12:49PM (#24384945)
They’re not variables until they’ve been specified a type, which is at the point you first assign to the memory in a typed fashion I believe. It’s significantly more pedantic than the first line in an introductory text will go into, though ;)
Re:Massacring C Pointers (2018) by grayhatter on Saturday September 05, 2020 @06:36PM (#24387401)
Nah, that's wrong. A variable doesn't need a type. Case in point; void.
Re:Massacring C Pointers (2018) by icedchai on Saturday September 05, 2020 @07:32PM (#24387694)
All variables have types in C. You can't declare a "void" variable. You can declare a void function. Try assigning it to a variable. You can't. void pointers (void*) are a different story.
Re:Massacring C Pointers (2018) by eru on Sunday September 06, 2020 @05:41AM (#24390179)
So just the opposite of what the comment you replied to suggested:

'void' is a type, but in C values of the type void are not first class. Ie a function can return a value of type void, but you can't assign it to a variable.

Re:Massacring C Pointers (2018) by saagarjha on Saturday September 05, 2020 @07:24PM (#24387647)
I'm not sure what you mean, could you explain a bit more?
Re:Massacring C Pointers (2018) by eru on Sunday September 06, 2020 @05:39AM (#24390170)
Are you saying void is not a type?