In another thread this subject came up and I would like get some educated opinions on the issue. It was tangential to the original topic and I will do a little cut and pasting to set up the current topic, these cuts are of course out of context, but I'm not trying to be misleading, I just want to get to the meat...
While it is not practical to post all of the code from my reference, this morning I generated some code that illustrates the issue and does, in fact, represent my reference. That code, with some specific questions is in the next post - give me a few minutes to get it written and sent.
While it is not practical to post all of the code from my reference, this morning I generated some code that illustrates the issue and does, in fact, represent my reference. That code, with some specific questions is in the next post - give me a few minutes to get it written and sent.
The only reason I know this is because of a long head-banging session. I was writing a function that I wanted to send both unsigned char * and signed char *.
The compiler would not let me do this by giving me a warning or error along the lines of:
pointer targets in passing argument 1 of 'blahblah' differ in signedness [-Werror=pointer-sign]
because, of course, an unsigned character is a different type than a signed char, even though they were, in my case, always the same size.
I could have turned the error off with some compiler switch, I suppose, but that is always a bad idea for me.
I was not going to write two separate functions and I was also not going to always typecast one or the other (the less typecasting I do, the better).
So, I wrote the function prototype as blah_write(void * message); and it worked just fine. Maybe this was sloppy, but I don't see how, after reading about what the heck a pointer to void was. The function always knew what to do and it was the same thing regardless of whether it was a signed or unsigned char. I believed and still do, that it was the way to go.
@raymond: Sorry I cannot post code via my iPad but two identicle functions, one passing a void pointer, one passing a char pointer, yield different results when assigning a character.
The difference being assigning a character yeilds an error "illegal conversion between types."
C has very strong type checking, and type char* is not the same as a void* pointer.
How did you dereference the 'message' pointer within your blah_write() function? If your compiler is conforming at all, then you should have had to cast it to a pointer to a complete data type. Unless it was ONLY your prototype that had it declared as a void pointer and it was declared as a char (of one type or the other) within the function. Now THAT would have been sloppy!