discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: data type polymorphism


From: Scott Christley
Subject: Re: data type polymorphism
Date: Tue, 24 Mar 2015 15:25:12 -0500

Hi Riccardo,

Maxthon is not suggesting to pick a type during compile time, but instead use a 
macro to generate both cases in your code.  For your app it would be something 
like this where the macro has the code, and the C preprocessor is used to 
insert the code.  In reality you still have duplicate code.  I was aware of 
this solution but was interested to see if there was any alternatives.


#define PROCESS_IMAGE(DATATYPE) \
              DATATYPE    *srcData; \
              DATATYPE    *destData; \
              DATATYPE    *p1; \
              DATATYPE    *p2; \
              // etc.


  if ([srcImageRep bitsPerSample] == 8)
    {
        PROCESS_IMAGE(unsigned char)
    }
  else if ([srcImageRep bitsPerSample] == 16)
    {
        PROCESS_IMAGE(unsigned short)
    }


On Mar 24, 2015, at 2:05 PM, Riccardo Mottola <address@hidden> wrote:

> Hi Maxthon,
> 
> Maxthon Chan wrote:
>> If you need to keep your code strictly C you can emulate this by (ab)using 
>> #include and #define and #ifdef like this:
> 
> from what I can understand, your solution switches types at compile time.
> 
> I need instead to do that at runtime. I get an NSImageRepresentation, analyze 
> the bit depth and execute the same algorithm, but once on 8bit (char) and 
> once with 16bit (short).
> 
> Riccardo
> 
> _______________________________________________
> Discuss-gnustep mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/discuss-gnustep




reply via email to

[Prev in Thread] Current Thread [Next in Thread]