C - Typedef and function pointers

Started by
24 comments, last by Emmanuel Deloget 18 years, 1 month ago
Quote:Original post by Anonymous Poster
all must bow down and worship the mastermind, for he is the chosen one!
always correct, always right, always so full of himself

I certainly hope this was a jab at the previous AP, and not Enigma, who is completely correct. If you don't believe him, feel free to run some tests...sizeof works for pointers too.

CM
Advertisement
Quote:Original post by SiCrane
It's a good coding habit; when you take the address of a pointer to member function, the ampersand is necessary.


Quote:Original post by SiCrane
And your point is that I should ignore good coding habits just because the file has a .c extension?


Really now you're going overboard. This is just a matter of style and of choice. Not having to take the address explicitly is provided as a convenience, just like easily being able to get the address of the first element of an array. I don't see anyone arguing that whenever you pass an array to a function by iterator to the first element that you explicitly go &my_array[0]. If you want to add extra work for yourself, go ahead, but don't push that on I_Smell_Tuna or LessBread or anyone else. That's just silly. Just explain why you dislike one way and let him decide. I usually explicitly write & when taking the address of a function as well, but who cares if you don't. It's not a bad habbit and it's not deprecated, it's just a different style.
C++ fun:

typedef bool(func)(bool);func x;struct Z {  func method;};void nada(){	func* b;	b = &x}bool Z::method(bool) {return true;}bool x(bool) {return false;}


Why typedef a function pointer, when you can typedef a function?
Quote:Original post by Polymorphic OOP
Really now you're going overboard.

Please notice that I'm critisizing his crappy reasoning in his objection rather than the objection itself. If you want to object don't just say "C++ HABITS BAD!" Give a reason why you think it's bad. LessBread did not advance a valid reason, he just brought forward meaningless generalities that ignored the fact that C and C++ have a sufficiently common lineage that good habits in either language will come from just the fact the other language exists, such as the #ifdef __cplusplus, and decided to make a snide comment rather than justify his stance.

Quote:
Not having to take the address explicitly is provided as a convenience, just like easily being able to get the address of the first element of an array.

And so are conversion operators, and those are rarely good form. And so is ignoring the return value of system calls. Just because the language lets you get away with it doesn't necessarily mean it's a good idea.

Quote:
I don't see anyone arguing that whenever you pass an array to a function by iterator to the first element that you explicitly go &my_array[0].

That isn't an apples to apples comparison. First off, my_array isn't hungarian, so someone using that array name wouldn't be using those kinds of C type matching skills. In any case, if the array name was properly decorated, you wouldn't need the &, because the type prefix is there, which will satisfy the instintictive pattern matching. In contrast, function names are not decorated with type prefixes under Hungarian, so a the & is needed to match against the pointer type assignment of the pointer type.

Now then, if you want to argue that Hungarian, even in C, isn't a good idea, I'll accept that as a rationale that you wouldn't use the & to prefix the function pointer assignment. I'll wonder how you get any meaningful work done in C, but I'll accept it. If you want to say that your doctor ordered you to avoid using & and other symbols because of carpal tunnel, then ok, fine. I'm sure there are other objections I'll find reasonable. However, vague cries of "C++ HABITS BAD!" is not an acceptable objection.
Quote:Original post by SiCrane
Quote:Original post by Polymorphic OOP
Really now you're going overboard.

Please notice that I'm critisizing his crappy reasoning in his objection rather than the objection itself. If you want to object don't just say "C++ HABITS BAD!" Give a reason why you think it's bad. LessBread did not advance a valid reason, he just brought forward meaningless generalities that ignored the fact that C and C++ have a sufficiently common lineage that good habits in either language will come from just the fact the other language exists, such as the #ifdef __cplusplus, and decided to make a snide comment rather than justify his stance.


I started out by simply saying that the & wasn't needed because the fact is that in this situation it's not. Good coding habit might indicate it's use, but it doesn't make it a requirement. Moreover, focusing attention on your statement about pointers to member functions - which don't exist in C - doesn't constitute bringing foward a meaningless generality. Again, that has nothing to do with good coding habits, so I don't see why you felt compelled to retreat to the shelter of good coding habits unless it was to escape acknowledging clear differences in the languages.

And how did this stupid thread get necroed anyway?
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Quote:Original post by LessBread
And how did this stupid thread get necroed anyway?


This should be the last statement of the thread. Who wants to argue about what is a good/bad habit in the prosciuto programming language ? That's rather useless. Both points are valid, and you are too heated to continue the discussion right now.

Wow. It looks like I'm moderating the moderators.

This topic is closed to new replies.

Advertisement