Live data from Hacker News

Everything you need to know about pointers in C (2010)

boredzo.org

21–25 of 25 posts

Re: Everything you need to know about pointers in C (2010)

#21
post #18
post #17

Earlier quoted context omitted.

Besides writing "int *p" instead of "int* p" I also always use one line per variable declaration, which should avoid confusion when the first style is used. But that's my personal preference. Edit: corrected code quotation.

When quoting code, leave a line and indent by two spaces.

Sorry, will do so in the future. Thx.

Re: Everything you need to know about pointers in C (2010)

#22

The time [0] I found out about ptr_b in int* ptr_a, ptr_b; isn't actually initialized as a pointer I changed all my C code to marking * before the variable name, fun times. It's helpful to think int as the base type and * the indicator of functionality like [] and (). Also just found out the author was the developer of Adium [1], which is one of my favorite softwares (best logo) on macOS. [0] http://c-faq.com/decl/ch…

I used to use that years ago! I had to stop when everyone moved over to Facebook Chat (what became Messenger) and eventually made a breaking change Adium couldn't support.

Re: Everything you need to know about pointers in C (2010)

#23
post #5

> void pointers are incremented or decremented by 1 byte. No, void pointer arithmetic is not allowed by the C standard: https://stackoverflow.com/questions/3523145/pointer-arithmet...

That answer does mention that GCC permits it as an extension. If the author uses GCC, maybe that’s where the confusion comes from?

But then he also writes that "sizeof(void) is illegal".

OTOH, GCC documentation says "sizeof is also allowed on void and on function types, and returns 1".

Re: Everything you need to know about pointers in C (2010)

#24
post #6

Earlier quoted context omitted.

Posting C++ in a thread about C is odd. In C it's: #include int main(void) { printf("%zu\n", sizeof (int *)); return 0; }

There's a double-quote character missing.

Thanks. I suck at posting from my phone. Edited.

Re: Everything you need to know about pointers in C (2010)

#25
post #17

The time [0] I found out about ptr_b in int* ptr_a, ptr_b; isn't actually initialized as a pointer I changed all my C code to marking * before the variable name, fun times. It's helpful to think int as the base type and * the indicator of functionality like [] and (). Also just found out the author was the developer of Adium [1], which is one of my favorite softwares (best logo) on macOS. [0] http://c-faq.com/decl/ch…

Besides writing "int *p" instead of "int* p" I also always use one line per variable declaration, which should avoid confusion when the first style is used. But that's my personal preference. Edit: corrected code quotation.

"int* p" really grinds my gears
Post reply on HN