conversion of unix codes to VC++ codes
-
Hello there, I tried to incorporate the following code segments in a VC++ project, and to compile it in Visual Studio. There were compiling errors beyond my comprehension. Any help are appreciated. typedef void biasFn (void *image, void *bias, uint32 pixels); #define subtract(bits) \ static void subtract##bits (void *i, void *b, uint32 pixels)\ {\ uint##bits *image = i;\ uint##bits *bias = b;\ while (pixels--) {\ *image = *image > *bias ? *image-*bias : 0;\ image++, bias++; \ } \ } subtract(8) subtract(16) subtract(32) static biasFn *lineSubtractFn (unsigned bits) { switch (bits) { case 8: return subtract8; case 16: return subtract16; case 32: return subtract32; } return NULL; }
-
Hello there, I tried to incorporate the following code segments in a VC++ project, and to compile it in Visual Studio. There were compiling errors beyond my comprehension. Any help are appreciated. typedef void biasFn (void *image, void *bias, uint32 pixels); #define subtract(bits) \ static void subtract##bits (void *i, void *b, uint32 pixels)\ {\ uint##bits *image = i;\ uint##bits *bias = b;\ while (pixels--) {\ *image = *image > *bias ? *image-*bias : 0;\ image++, bias++; \ } \ } subtract(8) subtract(16) subtract(32) static biasFn *lineSubtractFn (unsigned bits) { switch (bits) { case 8: return subtract8; case 16: return subtract16; case 32: return subtract32; } return NULL; }
Bugslayer1 wrote: There were compiling errors... I give up. What were the errors?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
Bugslayer1 wrote: There were compiling errors... I give up. What were the errors?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
When the VC++ compiles the following lines. It throws error messages: subtract(8) subtract(16) subtract(32) error C2440: 'initializing' : cannot convert from 'void *' to 'unsigned char *' Conversion from 'void*' to pointer to non-'void' requires an explicit cast I also had hard to understand these lines of codes.
-
When the VC++ compiles the following lines. It throws error messages: subtract(8) subtract(16) subtract(32) error C2440: 'initializing' : cannot convert from 'void *' to 'unsigned char *' Conversion from 'void*' to pointer to non-'void' requires an explicit cast I also had hard to understand these lines of codes.
Ok, what is
subtract()
expecting? You need to change lines in thesubtract()
macro to:uint##bits *image = (uint##bits *) i;\
uint##bits *bias = (uint##bits *) b;\
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
Ok, what is
subtract()
expecting? You need to change lines in thesubtract()
macro to:uint##bits *image = (uint##bits *) i;\
uint##bits *bias = (uint##bits *) b;\
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
I do not know until I understand these lines of codes. The codes were compiled under Unix system. Problem is that I had a hard time to read the code. Can you explain to me what these lines of codes do?
-
I do not know until I understand these lines of codes. The codes were compiled under Unix system. Problem is that I had a hard time to read the code. Can you explain to me what these lines of codes do?
Bugslayer1 wrote: Can you explain to me what these lines of codes do? No. You should be able to tell us what they do.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
Bugslayer1 wrote: Can you explain to me what these lines of codes do? No. You should be able to tell us what they do.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
No. I cannot. I got the code from libtiff http://www.libtiff.org[^]. One of the tools is tiffcp. I am trying to compile it using VC++.
-
No. I cannot. I got the code from libtiff http://www.libtiff.org[^]. One of the tools is tiffcp. I am trying to compile it using VC++.
I suggest using the /P compiler switch. It will expand that
subtract()
macro, and then you can see exactly what the problem is.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
Hello there, I tried to incorporate the following code segments in a VC++ project, and to compile it in Visual Studio. There were compiling errors beyond my comprehension. Any help are appreciated. typedef void biasFn (void *image, void *bias, uint32 pixels); #define subtract(bits) \ static void subtract##bits (void *i, void *b, uint32 pixels)\ {\ uint##bits *image = i;\ uint##bits *bias = b;\ while (pixels--) {\ *image = *image > *bias ? *image-*bias : 0;\ image++, bias++; \ } \ } subtract(8) subtract(16) subtract(32) static biasFn *lineSubtractFn (unsigned bits) { switch (bits) { case 8: return subtract8; case 16: return subtract16; case 32: return subtract32; } return NULL; }
-
I do not know until I understand these lines of codes. The codes were compiled under Unix system. Problem is that I had a hard time to read the code. Can you explain to me what these lines of codes do?
-
I suggest using the /P compiler switch. It will expand that
subtract()
macro, and then you can see exactly what the problem is.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
Thanks for your help to expand the codes into a readable fashion. I still have some probelms although I made some progress with some changes. typedef void biasFn (void *image, void *bias, uint32 pixels); static void subtract8 (uint8 *i, uint8 *b, uint32 pixels) { uint8 *image = i; uint8 *bias = b; while (pixels--) { *image = *image > *bias ? *image-*bias : 0; image++, bias++; } } static void subtract16 (uint16 *i, uint16 *b, uint32 pixels) { uint16 *image = i; uint16 *bias = b; while (pixels--) { *image = *image > *bias ? *image-*bias : 0; image++, bias++; } } static void subtract32 (uint32 *i, uint32 *b, uint32 pixels) { uint32 *image = i; uint32 *bias = b; while (pixels--) { *image = *image > *bias ? *image-*bias : 0; image++, bias++; } } static biasFn *lineSubtractFn (unsigned bits) { switch (bits) { case 8: return subtract8; case 16: return subtract16; case 32: return subtract32; } return 0; } ...... biasFn *subtractLine; TIFFGetField(in, 258, &sampleBits); subtractLine = lineSubtractFn (sampleBits); if (subtractLine) { ...... } ...... However, there are some errors I need to work out. Here are the error messages: e:\vc++\libtiff\src\tiff\3.7.2\tiff-3.7.2-src\tools\tiffcp\tiffcp.cpp(975) : error C2440: 'return' : cannot convert from 'void (__cdecl *)(unsigned char *,unsigned char *,unsigned long)' to 'void (__cdecl *)(void *,void *,unsigned long)' This conversion requires a reinterpret_cast, a C-style cast or function-style cast e:\vc++\libtiff\src\tiff\3.7.2\tiff-3.7.2-src\tools\tiffcp\tiffcp.cpp(976) : error C2440: 'return' : cannot convert from 'void (__cdecl *)(unsigned short *,unsigned short *,unsigned long)' to 'void (__cdecl *)(void *,void *,unsigned long)' This conversion requires a reinterpret_cast, a C-style cast or function-style cast e:\vc++\libtiff\src\tiff\3.7.2\tiff-3.7.2-src\tools\tiffcp\tiffcp.cpp(977) : error C2440: 'return' : cannot convert from 'void (__cdecl *)(unsigned long *,unsigned long *,unsigned long)' to 'void (__cdecl *)(void *,void *,unsigned long)' This conversion requires a reinterpret_cast, a C-style cast or function-style cast Any help is appreciated.
-
Thanks for your help to expand the codes into a readable fashion. I still have some probelms although I made some progress with some changes. typedef void biasFn (void *image, void *bias, uint32 pixels); static void subtract8 (uint8 *i, uint8 *b, uint32 pixels) { uint8 *image = i; uint8 *bias = b; while (pixels--) { *image = *image > *bias ? *image-*bias : 0; image++, bias++; } } static void subtract16 (uint16 *i, uint16 *b, uint32 pixels) { uint16 *image = i; uint16 *bias = b; while (pixels--) { *image = *image > *bias ? *image-*bias : 0; image++, bias++; } } static void subtract32 (uint32 *i, uint32 *b, uint32 pixels) { uint32 *image = i; uint32 *bias = b; while (pixels--) { *image = *image > *bias ? *image-*bias : 0; image++, bias++; } } static biasFn *lineSubtractFn (unsigned bits) { switch (bits) { case 8: return subtract8; case 16: return subtract16; case 32: return subtract32; } return 0; } ...... biasFn *subtractLine; TIFFGetField(in, 258, &sampleBits); subtractLine = lineSubtractFn (sampleBits); if (subtractLine) { ...... } ...... However, there are some errors I need to work out. Here are the error messages: e:\vc++\libtiff\src\tiff\3.7.2\tiff-3.7.2-src\tools\tiffcp\tiffcp.cpp(975) : error C2440: 'return' : cannot convert from 'void (__cdecl *)(unsigned char *,unsigned char *,unsigned long)' to 'void (__cdecl *)(void *,void *,unsigned long)' This conversion requires a reinterpret_cast, a C-style cast or function-style cast e:\vc++\libtiff\src\tiff\3.7.2\tiff-3.7.2-src\tools\tiffcp\tiffcp.cpp(976) : error C2440: 'return' : cannot convert from 'void (__cdecl *)(unsigned short *,unsigned short *,unsigned long)' to 'void (__cdecl *)(void *,void *,unsigned long)' This conversion requires a reinterpret_cast, a C-style cast or function-style cast e:\vc++\libtiff\src\tiff\3.7.2\tiff-3.7.2-src\tools\tiffcp\tiffcp.cpp(977) : error C2440: 'return' : cannot convert from 'void (__cdecl *)(unsigned long *,unsigned long *,unsigned long)' to 'void (__cdecl *)(void *,void *,unsigned long)' This conversion requires a reinterpret_cast, a C-style cast or function-style cast Any help is appreciated.
Notice that
lineSubtractFn()
is returning abiasFn*
, but the function addresses that are actually being returned (i.e.,subtract8
,subtract16
,subtract32
) have a different signature.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
Notice that
lineSubtractFn()
is returning abiasFn*
, but the function addresses that are actually being returned (i.e.,subtract8
,subtract16
,subtract32
) have a different signature.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
The lines 975-977 are case 8: return subtract8; case 16: return subtract16; case 32: return subtract32;
-
The lines 975-977 are case 8: return subtract8; case 16: return subtract16; case 32: return subtract32;
As I indicated, those three functions do not have the same signature as the
biasFn
type.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown