Should I redesign my code when my colleague says so?
- by Kirill V. Lyadvinsky
I wrote a function recently (with help of one guy from SO) that finds maximum of two ints. Here is the code:
long get_max (long(*a)(long(*)(long(*)()),long(*)(long(*)(long**))), long(*b)(long(*)
(long(*)()),long*,long(*)(long(*)()))){return (long)((((long(*)(long(*)(long(*)()),long(
*)(long(*)())))a)> ((long(*)(long(*)(long(*)()),long(*)(long(*)())))b))?((long(*)(
long(*)(long(*)()),long(*)(long(*)())))a):((long(*)(long(*)(long(*)()),long(*)(long(*)(
))))b));}
int main()
{
long x = get_max(
(long(*)(long(*)(long(*)()),long(*)(long(*)(long**)))) 500,
(long(*)(long(*)(long(*)()),long*,long(*)(long(*)()))) 100 );
cout << x << endl; // print 500 as expected
return 0;
}
It works fine, but my colleague says that I shouldn't use C style casts. But I think that all that modern static_cast's and reinterpret_cast's will make my code too cumbersome. Who's right? Should I redesign my code using C++ style casts or is original code OK?
EDIT: For those who marks this question as not a question I'll try to be more clear: should I use C++ style cast instead of C style cast in the code above?