Regarding typedef

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Oskars Salnins

    #1

    Regarding typedef

    Hi
    What does the statement:

    typedef unsigned my_type_name;

    mean? Cannot find an answer to this in ordinary books on C.

    --
    Thanks,
    Osk
  • lndresnick@gmail.com

    #2
    Re: Regarding typedef

    Oskars Salnins wrote:[color=blue]
    > Hi
    > What does the statement:
    >
    > typedef unsigned my_type_name;
    >
    > mean? Cannot find an answer to this in ordinary books on C.
    >
    > --
    > Thanks,
    > Osk[/color]

    It creates a new name for the unsigned int data type. You could then
    use
    it in place of a type, e.g.
    my_type_name i = 0;

    is the now the same as
    unsigned i = 0;
    or
    unsigned int i = 0;

    I assume you were confused by the fact that "int" to be inferred? That
    is a bit odd, but that is how it works. You can likewise say "signed
    short" meaning
    "signed short int".

    -David

    Comment

    • Martin Ambuhl

      #3
      Re: Regarding typedef

      Oskars Salnins wrote:[color=blue]
      > Hi
      > What does the statement:
      >
      > typedef unsigned my_type_name;
      >
      > mean? Cannot find an answer to this in ordinary books on C.[/color]

      It means that 'my_type_name' is now a synonym for 'unsigned int'.
      'unsigned' here is short for 'unsigned int'.

      Comment

      • Angrez Singh

        #4
        Re: Regarding typedef

        Hi,

        It means that you have given a new name to old unsigned data type.
        So you can use it instead of unsigned.

        For e.g.:
        typedef unsigned my_unsigned;

        my_unsigned x = 0;

        now x will be of type unsigned.

        Regards,
        Angrez

        Comment

        • vijoeyz@gmail.com

          #5
          Re: Regarding typedef


          Angrez Singh wrote:[color=blue]
          > Hi,
          >
          > It means that you have given a new name to old unsigned data type.
          > So you can use it instead of unsigned.
          >
          > For e.g.:
          > typedef unsigned my_unsigned;
          >
          > my_unsigned x = 0;
          >
          > now x will be of type unsigned.
          >
          > Regards,
          > Angrez[/color]

          Yes.

          typedef is an useful construct that the language provides. For
          example,
          just to explain the typedef, Symbian OS C++ provides generic data
          types:

          "TInt32, TInt16 and TInt8 map onto C++ built-in types in most
          implementations .
          These types should only be used where the size of the integer is of
          first
          importance."


          Here, the type definition could take the following form:

          typedef int TInt32;
          typedef short TInt16;
          typedef char TInt8;

          Using typedef's in such manner provides an easy inference, ease of
          portability,
          etc.


          Kind regards,

          --
          Vijay Kumar R. Zanvar
          C FAQs - http://geocities.com/vijoeyz/faq/

          Comment

          Working...