Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Random things that piss you off about C++

Name: Anonymous 2004-12-31 9:02

I hate how function declarations and function definitions usually don't look the same. For example

Declaration:
virtual void doShit()

Definition:
void MyNamespace::MyClass::doShit()

Name: Anonymous 2010-10-03 14:14

>>77
I'm referring to function calls, not plain assignments, and I think you are vastly underestimating the usefulness of a special keyword or macro to identify a pointer type.

Suppose you have a function mutate() which takes an array, its size, a scalar value to multiply each value, and maybe another array with which to perform an entry-wise sum. You know that with this particular API, which with you are only passingly familiar, that its functions all take an array and size as the first parameter, but beyond that, the parameters are less well-defined.

Now, if you see this function being used once as:
int x[4] = {29, 315, 4929, 0};
mutate(x, 4, 0, NULL);

then you will be able to figure out that it's basically zeroing out the array. (Admittedly, this is a rather pedantic example, but suppose the values were not plain integers but rather some special type which could not simply be cleared out with memset, or perhaps this is running on special hardware where such an operation is faster than memset, etc.) Given your passing familiarity with the nature of the function, if you needed later to use this function to perform a scalar multiply, you could write mutate(x, 4, 6, NULL); and it would function as expected.

If, on the other hand, the code used 0 haphazardly instead of NULL like it should, you would be faced with the visually ambiguous mutate(x, 4, 0, 0); and you would need to either stop and look up the documentation or hunt around for the declaration in the header files (which, depending on the complexity of the system and the adequacy of the documentation, might prove to be a time-consuming task), or make a random guess at whether the first or second 0 was the pointer type.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List