typedef for portability

I'm starting work on my bigint thing again...and I'm shooting for portability. Now, the question is on the types. Now I know that redefining types for the sake of portability is important for this...

However, I have a problem that might popup...this bigint things is obviously a component, so, since its compiled with other components, or its host program, it might run into a typdef of the same name. Such is of greater possibility if I use common names, like uint16 or so...

Any solution or idea, or should I just make a more safe name (like sint_t_unit16 or something...)

{2}rIng

Comments

  • : I'm starting work on my bigint thing again...and I'm shooting for
    : portability. Now, the question is on the types. Now I know that
    : redefining types for the sake of portability is important for this...
    :
    : However, I have a problem that might popup...this bigint things is
    : obviously a component, so, since its compiled with other components,
    : or its host program, it might run into a typdef of the same name.
    : Such is of greater possibility if I use common names, like uint16 or
    : so...
    :
    : Any solution or idea, or should I just make a more safe name (like
    : sint_t_unit16 or something...)
    :
    : {2}rIng

    If you come accross a component are something that might cause naming
    conflicts, just use the preprocessor to hide your typedef names,
    or #undef them before you typedef them.

    I personally append a _t to typedef type names, but then again
    uint16_t is just as common as uint16.
  • : : I'm starting work on my bigint thing again...and I'm shooting for
    : : portability. Now, the question is on the types. Now I know that
    : : redefining types for the sake of portability is important for this...
    : :
    : : However, I have a problem that might popup...this bigint things is
    : : obviously a component, so, since its compiled with other components,
    : : or its host program, it might run into a typdef of the same name.
    : : Such is of greater possibility if I use common names, like uint16 or
    : : so...
    : :
    : : Any solution or idea, or should I just make a more safe name (like
    : : sint_t_unit16 or something...)
    : :
    : : {2}rIng
    :
    : If you come accross a component are something that might cause naming
    : conflicts, just use the preprocessor to hide your typedef names,
    : or #undef them before you typedef them.
    :
    : I personally append a _t to typedef type names, but then again
    : uint16_t is just as common as uint16.

    can you #undef typedef names...I thought they are compiler handled, but #undef is for preproccessor...

    Anyhow, heres another predicament...See, lets say I want to return a int that acts as a bitset from a few functions...now, to do that, a certain number of bits is required for the return type...but the thing is the type is returned...so the user of te component must have this type defined for itself...

    I tried solving it the stupid way, redesigning my functions so they don't have to return bitsets(making them only have one status to return, thus, a single value)...

    {2}rIng
  • : : : I'm starting work on my bigint thing again...and I'm shooting for
    : : : portability. Now, the question is on the types. Now I know that
    : : : redefining types for the sake of portability is important for this...
    : : :
    : : : However, I have a problem that might popup...this bigint things is
    : : : obviously a component, so, since its compiled with other components,
    : : : or its host program, it might run into a typdef of the same name.
    : : : Such is of greater possibility if I use common names, like uint16 or
    : : : so...
    : : :
    : : : Any solution or idea, or should I just make a more safe name (like
    : : : sint_t_unit16 or something...)
    : : :
    : : : {2}rIng
    : :
    : : If you come accross a component are something that might cause naming
    : : conflicts, just use the preprocessor to hide your typedef names,
    : : or #undef them before you typedef them.
    : :
    : : I personally append a _t to typedef type names, but then again
    : : uint16_t is just as common as uint16.
    :
    : can you #undef typedef names...I thought they are compiler handled,
    : but #undef is for preproccessor...

    [color=Blue]Im assuming you never #undef new before?[/color] ;-)

    : Anyhow, heres another predicament...See, lets say I want to return a
    : int that acts as a bitset from a few functions...now, to do that, a
    : certain number of bits is required for the return type...but the
    : thing is the type is returned...so the user of te component must
    : have this type defined for itself...

    [color=Blue]If a routine needs to return a bit pattern, decide how many bits
    it should return. ...Lets say, 32.

    Pick a data type thats 32bits (Integers on 32bt systems), and have it
    return that type. Then mask the value to test the bits.

    Im not sure what you mean by [b]the user of te component must
    have this type defined for itself[/b] -- Why?
    [/color]
    : I tried solving it the stupid way, redesigning my functions so they
    : don't have to return bitsets(making them only have one status to
    : return, thus, a single value)...

    [color=Blue]I coinsider that a better method. If you can find a method that
    isnt platform specific, and easier to modify, use it![/color]
  • : : : : I'm starting work on my bigint thing again...and I'm shooting for
    : : : : portability. Now, the question is on the types. Now I know that
    : : : : redefining types for the sake of portability is important for this...
    : : : :
    : : : : However, I have a problem that might popup...this bigint things is
    : : : : obviously a component, so, since its compiled with other components,
    : : : : or its host program, it might run into a typdef of the same name.
    : : : : Such is of greater possibility if I use common names, like uint16 or
    : : : : so...
    : : : :
    : : : : Any solution or idea, or should I just make a more safe name (like
    : : : : sint_t_unit16 or something...)
    : : : :
    : : : : {2}rIng
    : : :
    : : : If you come accross a component are something that might cause naming
    : : : conflicts, just use the preprocessor to hide your typedef names,
    : : : or #undef them before you typedef them.
    : : :
    : : : I personally append a _t to typedef type names, but then again
    : : : uint16_t is just as common as uint16.
    : :
    : : can you #undef typedef names...I thought they are compiler handled,
    : : but #undef is for preproccessor...
    :
    : [color=Blue]Im assuming you never #undef new before?[/color] ;-)

    [color=Red]Or may be I don't really understand...can you pls explain what you meant by "#undef them before you typedef them"...I know how to hide..but...ugh sorry...[/color]


    :
    : : Anyhow, heres another predicament...See, lets say I want to return a
    : : int that acts as a bitset from a few functions...now, to do that, a
    : : certain number of bits is required for the return type...but the
    : : thing is the type is returned...so the user of te component must
    : : have this type defined for itself...
    :
    : [color=Blue]If a routine needs to return a bit pattern, decide how
    : many bits
    : it should return. ...Lets say, 32.
    :
    : Pick a data type thats 32bits (Integers on 32bt systems), and have it
    : return that type. Then mask the value to test the bits.
    :
    : Im not sure what you mean by [b]the user of te component must
    : have this type defined for itself[/b] -- Why?
    : [/color]

    [color=Red](the new tag thingy is..intresting)Screw what I said...it doesn't make sense what I was thinking(lol XD)...[/color]

    : : I tried solving it the stupid way, redesigning my functions so they
    : : don't have to return bitsets(making them only have one status to
    : : return, thus, a single value)...
    :
    : [color=Blue]I coinsider that a better method. If you can find a
    : method that
    : isnt platform specific, and easier to modify, use it![/color]

    I thought that this was messy, to redesign everything on the sake of one problem...well I am a noob...or idk.

    Hows this

    [code]
    #if sizeof(unsigned short) >= 2
    typedef _sint_uint16_ unsigned short

    #elif sizeof(unsigned int) >= 2
    typedef _sint_uint16_ unsigned int

    #elif sizeof(unsigned long) >= 2
    typedef _sint_uint16_ unsigned long

    #else
    #error "No primitive type has a byte length of at least 2. This component cannot complie on this platform."
    #endif
    [/code]

    Is this hunky-dori?

    thnx
    {2}rIng
  • : [code]:
    : #if sizeof(unsigned short) >= 2
    : typedef _sint_uint16_ unsigned short
    :
    : #elif sizeof(unsigned int) >= 2
    : typedef _sint_uint16_ unsigned int
    :
    : #elif sizeof(unsigned long) >= 2
    : typedef _sint_uint16_ unsigned long
    :
    : #else
    : #error "No primitive type has a byte length of at least 2. This component cannot complie on this platform."
    : #endif
    : [/code]:
    :
    : Is this hunky-dori?
    :
    : thnx
    : {2}rIng
    [code][/code]
    I never thought about that method :-)
    [code][/code]
    I useually do it based off platform.
    [code][/code]
    Or, just use the ANSI [b]stdint.h[/b] :-)
    [code][/code]
    As for undefining a symbol:
    [code]
    #undef foo
    typedef unsigned int foo;
    [/code]
  • : : [code]: :
    : : #if sizeof(unsigned short) >= 2
    : : typedef _sint_uint16_ unsigned short
    : :
    : : #elif sizeof(unsigned int) >= 2
    : : typedef _sint_uint16_ unsigned int
    : :
    : : #elif sizeof(unsigned long) >= 2
    : : typedef _sint_uint16_ unsigned long
    : :
    : : #else
    : : #error "No primitive type has a byte length of at least 2. This component cannot complie on this platform."
    : : #endif
    : : [/code]: :
    : :
    : : Is this hunky-dori?
    [code][/code]
    [color=Green]ige> This won't work. "sizoof(...)" operator is evaluated at runtime, and not at compile time. [/color]
    [code][/code]
    : :
    : : thnx
    : : {2}rIng
    : [code]: [/code]:
    : I never thought about that method :-)
    : [code]: [/code]:
    : I useually do it based off platform.
    : [code]: [/code]:
    : Or, just use the ANSI [b]stdint.h[/b] :-)
    : [code]: [/code]:
    : As for undefining a symbol:
    : [code]:
    : #undef foo
    : typedef unsigned int foo;
    : [/code]:

  • : : : [code]: : :
    : : : #if sizeof(unsigned short) >= 2
    : : : typedef _sint_uint16_ unsigned short
    : : :
    : : : #elif sizeof(unsigned int) >= 2
    : : : typedef _sint_uint16_ unsigned int
    : : :
    : : : #elif sizeof(unsigned long) >= 2
    : : : typedef _sint_uint16_ unsigned long
    : : :
    : : : #else
    : : : #error "No primitive type has a byte length of at least 2. This component cannot complie on this platform."
    : : : #endif
    : : : [/code]: : :
    : : :
    : : : Is this hunky-dori?
    : [code]: [/code]:
    : [color=Green]ige> This won't work. "sizoof(...)" operator is
    : evaluated at runtime, and not at compile time. [/color]
    : [code]: [/code]:
    : : :
    : : : thnx
    : : : {2}rIng
    : : [code]: : [/code]: :
    : : I never thought about that method :-)
    : : [code]: : [/code]: :
    : : I useually do it based off platform.
    : : [code]: : [/code]: :
    : : Or, just use the ANSI [b]stdint.h[/b] :-)
    : : [code]: : [/code]: :
    : : As for undefining a symbol:
    : : [code]: :
    : : #undef foo
    : : typedef unsigned int foo;
    : : [/code]: :
    :
    :

    [code]
    typedef int uint16;
    #undef uint16

    typedef int uint16;

    uint16 a;

    int main(){
    a=2;

    }
    [/code]

    Then should this compile? I didn't on my computer.
    {2}rIng
  • : [code]:
    : typedef int uint16;
    : #undef uint16
    :
    : typedef int uint16;
    :
    : uint16 a;
    :
    : int main(){
    : a=2;
    :
    : }
    : [/code]:
    :
    : Then should this compile? I didn't on my computer.
    : {2}rIng

    Interesting... It works fine for me (Visual Studio 2005
    and DJGPP GCC).

    What compilier do you have?

    TurboC doesnt seem to like it, which may emphisize its C++
    specific. (Not C)
  • : : [code]: :
    : : typedef int uint16;
    : : #undef uint16
    : :
    : : typedef int uint16;
    : :
    : : uint16 a;
    : :
    : : int main(){
    : : a=2;
    : :
    : : }
    : : [/code]: :
    : :
    : : Then should this compile? I didn't on my computer.
    : : {2}rIng
    :
    : Interesting... It works fine for me (Visual Studio 2005
    : and DJGPP GCC).
    :
    : What compilier do you have?
    :
    : TurboC doesnt seem to like it, which may emphisize its C++
    : specific. (Not C)

    OH!! THis is a cpp thing...i renamed the file to cpp and it compiled...

    I'm doing this component in C...sorry, I probably should of specified that.
    {2}rIng
  • : OH!! THis is a cpp thing...i renamed the file to cpp and it
    : compiled...
    :
    : I'm doing this component in C...sorry, I probably should of
    : specified that.
    : {2}rIng

    Ah :-)

    If its C, you might need to define the types in the preprocessor:
    [code]
    #undef int32_t
    #undef int64_t

    #ifdef _WIN32
    # define int32_t int // On Win32, sizeof (int)==32 bits
    # define int64_t long int
    #elif _WIN64
    # define int32_t unsigned short // I think
    # define int64_t int
    #endif
    [/code]
    int32_t is guaranteed to be a 32bit on both Win32 and Win64
    platforms.

    [hr]
    [size=1][leftbr].:EvolutionEngine[rightbr][leftbr].:MicroOS Operating System[rightbr][leftbr][link=http://www.mt2002.sitesled.com]Website[/link]
    [/size]
  • : : OH!! THis is a cpp thing...i renamed the file to cpp and it
    : : compiled...
    : :
    : : I'm doing this component in C...sorry, I probably should of
    : : specified that.
    : : {2}rIng
    :
    : Ah :-)
    :
    : If its C, you might need to define the types in the preprocessor:
    : [code]:
    : #undef int32_t
    : #undef int64_t
    :
    : #ifdef _WIN32
    : # define int32_t int // On Win32, sizeof (int)==32 bits
    : # define int64_t long int
    : #elif _WIN64
    : # define int32_t unsigned short // I think
    : # define int64_t int
    : #endif
    : [/code]:
    : int32_t is guaranteed to be a 32bit on both Win32 and Win64
    : platforms.
    :
    : [hr]
    : [size=1][leftbr].:EvolutionEngine[rightbr][leftbr].:MicroOS
    : Operating
    : System[rightbr][leftbr][link=http://www.mt2002.sitesled.com]Website[/
    : link]
    : [/size]

    [code][/code]
    [color=Green]
    ige>
    Yes, that (#define) thing is correct.
    [code][/code]
    But what was this following piece of code supposed to do (this was posted before)?
    [code][/code]
    undefining a typedef?

    [code]: : typedef int uint16;
    : : #undef uint16
    : :
    : : typedef int uint16;
    : :
    : : uint16 a;
    : :
    : : int main(){
    : : a=2;
    : :
    : : }[/code][/color]

  • : [code]: [/code]:
    : [color=Green]
    : ige>
    : Yes, that (#define) thing is correct.
    : [code]: [/code]:
    : But what was this following piece of code supposed to do (this was
    : posted before)?
    : [code]: [/code]:
    : undefining a typedef?
    :
    : [code]: : : typedef int uint16;
    : : : #undef uint16
    : : :
    : : : typedef int uint16;
    : : :
    : : : uint16 a;
    : : :
    : : : int main(){
    : : : a=2;
    : : :
    : : : }[/code]: [/color]
    :

    It undefines a type, just like its C #define counterpart.
    C++ treats typedef as just defined types, hence yes--you can
    #undef a typedef. This is C++ only though.

    [hr][size=1][leftbr].:EvolutionEngine[rightbr][leftbr].:MicroOS Operating System[rightbr][leftbr][link=http://www.mt2002.sitesled.com]Website[rightbr][/link][/size]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories