Re: Wrong-but-not-incorrect code
dj3vande@csclub .uwaterloo.ca (Dave Vandervies) wrote in message news:<d1cv00$hu f$1@rumours.uwa terloo.ca>...[color=blue]
> Seen in a chunk of code I was looking at recently (not mine!):
> --------
> char* imgfilename[100];
> sprintf((char*) imgfilename, "mask%d.dib ", params.profile) ;
> ReadImage((char *)imgfilename);
> --------
> (ReadImage is another part of the program's code that does exactly what
> the reasonable reader would expect.)
>
> For the CLC readers:
> Can you, by artifical construction or actual experience, come up with
> something that's more Wrong and yet still manages to be correct code
> that performs the intended task?
>
>
> dave[/color]
There is some particularly contorted code in the message cracker
header windowsx.h in MS Windows that works. For instance:-
#define HANDLE_WM_INITD IALOG(hwnd, wParam, lParam, fn) \
(LRESULT)(DWORD )(UINT)(BOOL)(f n)((hwnd), (HWND)(wParam), lParam)
Not that this is totally wrongheaded unlike the code you mentioned
above. It's just mildly derranged.
It's difficult looking at pieces of code like that you posted.
Sometimes pieces work, but are bad style, others work but are
undefined behaviour, still others are bugs but just happen to work.
When code is contorted it's very hard to tell which is which.
dj3vande@csclub .uwaterloo.ca (Dave Vandervies) wrote in message news:<d1cv00$hu f$1@rumours.uwa terloo.ca>...[color=blue]
> Seen in a chunk of code I was looking at recently (not mine!):
> --------
> char* imgfilename[100];
> sprintf((char*) imgfilename, "mask%d.dib ", params.profile) ;
> ReadImage((char *)imgfilename);
> --------
> (ReadImage is another part of the program's code that does exactly what
> the reasonable reader would expect.)
>
> For the CLC readers:
> Can you, by artifical construction or actual experience, come up with
> something that's more Wrong and yet still manages to be correct code
> that performs the intended task?
>
>
> dave[/color]
There is some particularly contorted code in the message cracker
header windowsx.h in MS Windows that works. For instance:-
#define HANDLE_WM_INITD IALOG(hwnd, wParam, lParam, fn) \
(LRESULT)(DWORD )(UINT)(BOOL)(f n)((hwnd), (HWND)(wParam), lParam)
Not that this is totally wrongheaded unlike the code you mentioned
above. It's just mildly derranged.
It's difficult looking at pieces of code like that you posted.
Sometimes pieces work, but are bad style, others work but are
undefined behaviour, still others are bugs but just happen to work.
When code is contorted it's very hard to tell which is which.
Comment