Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. conversion of unix codes to VC++ codes

conversion of unix codes to VC++ codes

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++visual-studiohelpquestion
14 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D David Crow

    Ok, what is subtract() expecting? You need to change lines in the subtract() 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

    B Offline
    B Offline
    Bugslayer1
    wrote on last edited by
    #5

    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?

    D B 2 Replies Last reply
    0
    • B Bugslayer1

      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?

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #6

      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

      B 1 Reply Last reply
      0
      • D David Crow

        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

        B Offline
        B Offline
        Bugslayer1
        wrote on last edited by
        #7

        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++.

        D 1 Reply Last reply
        0
        • B Bugslayer1

          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++.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #8

          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

          B 1 Reply Last reply
          0
          • B Bugslayer1

            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; }

            B Offline
            B Offline
            Bob Stanneveld
            wrote on last edited by
            #9

            Using macro's to generate functions like that, is very poor programming practice! besides that, the type uintXX where XX is a number is not available in VC, use unsigned __intXX instead. Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

            1 Reply Last reply
            0
            • B Bugslayer1

              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?

              B Offline
              B Offline
              Bob Stanneveld
              wrote on last edited by
              #10

              Why, for your own sake, do you compile and use code, that you don't even know what it's doing? :confused: Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

              1 Reply Last reply
              0
              • D David Crow

                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

                B Offline
                B Offline
                Bugslayer1
                wrote on last edited by
                #11

                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.

                D 1 Reply Last reply
                0
                • B Bugslayer1

                  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.

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #12

                  Notice that lineSubtractFn() is returning a biasFn*, 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

                  B 1 Reply Last reply
                  0
                  • D David Crow

                    Notice that lineSubtractFn() is returning a biasFn*, 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

                    B Offline
                    B Offline
                    Bugslayer1
                    wrote on last edited by
                    #13

                    The lines 975-977 are case 8: return subtract8; case 16: return subtract16; case 32: return subtract32;

                    D 1 Reply Last reply
                    0
                    • B Bugslayer1

                      The lines 975-977 are case 8: return subtract8; case 16: return subtract16; case 32: return subtract32;

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #14

                      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

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups