u_long valid C?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joe Van Dyk

    u_long valid C?

    u_long isn't a valid C type, right? (should be unsigned long, as far as
    I know)

    Joe
  • jjf@bcs.org.uk

    #2
    Re: u_long valid C?


    Joe Van Dyk wrote:[color=blue]
    > u_long isn't a valid C type, right? (should be unsigned long, as far as
    > I know)[/color]

    It's not a C type, but the programmer may have used typedef to make it
    a synonym for a C type. What it is, or should or shouldn't be, depends
    on the programmer.

    Comment

    • Ian Collins

      #3
      Re: u_long valid C?

      Joe Van Dyk wrote:[color=blue]
      > u_long isn't a valid C type, right? (should be unsigned long, as far as
      > I know)
      >[/color]
      Yes. u_long might be a typedef for unsigned long in some environments.

      --
      Ian Collins.

      Comment

      • Keith Thompson

        #4
        Re: u_long valid C?

        Joe Van Dyk <joe.vandyk@boe ing.com> writes:[color=blue]
        > u_long isn't a valid C type, right? (should be unsigned long, as far
        > as I know)[/color]

        u_long is a valid C type if it's been defined as a typedef.

        Doing so is, in my opinion, a bad idea. A typedef creates an alias
        for an existing type. The purpose is either to create a more
        meaningful name:
        typedef unsigned char byte;
        or to allow for the possibility that the underlying type might change:
        typedef int32 int;
        /* OR */
        typedef int32 long;

        u_long serves neither of these purposes. If you want unsigned long,
        use unsigned long; don't make your reader guess whether "u_long" means
        what it appears to mean. If there's any chance that your type
        "u_long" might be defined as something other than unsigned long, don't
        call it "u_long".

        --
        Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
        San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
        We must do something. This is something. Therefore, we must do this.

        Comment

        Working...