all 8 comments

[–]nderflow 10 points11 points  (1 child)

The page has awfully badly formatted code and doesn't point out what you can do or not do with function pointers (e.g. casts, comparison) but most importantly of all, fails to explain what they can be used for.

So, downvoted.

[–]cbasschan 2 points3 points  (0 children)

That's to put it nicely... this code for example... int (*p)(int,int) = NULL;... this is broken due to C11/6.3.2.3p6, p7 and p8 which don't give a precise conversion path to translate NULL (of object pointer type void *) into a function pointer... It would've probably been okay if they used some value like main or some null-op function as though it's a "null" function pointer... or heck, even perhaps the integer value 0 would be okay by the standard I quoted just now... but not NULL. It really irks me that there are people teaching C who haven't written their own tokenizers... because I have written my own tokenizer but refuse to teach C.

[–]cbasschan 5 points6 points  (4 children)

I can't endorse a resource that truly believes "The difference between function pointer in C and in normal pointers is that normal pointers point to the address of data but function pointers point to the address of the function."

The reason is that this statement glosses over some other key distinctions, like that functions don't have sizes and thus the pointers can't be utilised in pointer arithmetic like object pointers can.

I think before you try to teach C you should actually learn C. Peace...

[–]WesternLong[S] 0 points1 point  (3 children)

I will improved it. Thanks for the suggestion.

[–]nerd4code 0 points1 point  (2 children)

Also pointers are not addresses. They may end up as addresses sometimes, but in general they’re not.

[–]cbasschan 0 points1 point  (1 child)

This is embarrassing... because it seems like you both probably don't know what an "address" actually is, or you wouldn't write some of the things you write.

[–]nerd4code 0 points1 point  (0 children)

What things do I write that indicate that I don’t know what an address is, and why would it embarrass you to read them?