Hi
I'm transferring examples from Petzold Book to be compiled with PellesC.
(There are 23 chapters, so far I did only 15 chapters).
There is a problem with chapter 15- DibSect example.
I'm getting this error message:
//
C:\C\Projects\Petzold\p15-DibSect\DibSect.c(104): error #2140: Type error in argument 4 to 'CreateDIBSection'; expected 'void * *' but found 'unsigned char * *'.
*** Error code: 1 ***
//
How to fix it ?
Thanks
ly
With a cast to void **:
hBitmap = CreateDIBSection (NULL, pbmi, DIB_RGB_COLORS, (void **)&pBits, NULL, 0) ; //Line 104
PellesC unlike MSVC makes strict types checking as required by C standards.
MSVC is well known to be very lazy about these issues....
Hi frankie
Thanks a lot, now it works.
ly
This is a good time to make sure your code adheres to the c standard. While Pelles and VisualStudio don't follow aliasing rules, other compilers might( gcc does ), causing your code to produce undefined behavior on such compilers.
If a function requires a void** type, then the only standard compatible way is to pass that type. Types char** and void** are not compatible, such types may not alias, even with the cast.
So the correct solution would be:
void* temp = NULL ;
hBitmap = CreateDIBSection (NULL, pbmi, DIB_RGB_COLORS, &temp, NULL, 0) ;
pBits = temp ;
Hi neo313
Thanks for your explanation.
ly
Quote from: neo313 on June 15, 2014, 08:14:56 PM
If a function requires a void** type, then the only standard compatible way is to pass that type. Types char** and void** are not compatible, such types may not alias, even with the cast.
What means???
Quote from: ly47 on June 15, 2014, 11:37:06 PM
Hi neo313
Thanks for your explanation.
ly
No problem,
neo