unsigned int and unsigned long int

This is a discussion on unsigned int and unsigned long int within the C Programming forums, part of the General Programming Boards category; so even though I do: typedef long int int_4 and I do sizeof(int_4) that will be the same wherever machine ...

  1. #31
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    so even though I do:

    typedef long int int_4

    and I do sizeof(int_4) that will be the same wherever machine I am?? I guess not right

  2. #32
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by -EquinoX- View Post
    so even though I do:

    typedef long int int_4

    and I do sizeof(int_4) that will be the same wherever machine I am?? I guess not right
    That will not necessarily be the same on every machine.

  3. #33
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,435
    As tabstop mentions, no. That is why these typedefs exist in the first place. To map appropriate type into these typedefs so you can be sure about size.
    You have to use lots of #ifs and stuff to make it right for every machine.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #34
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    oh okay by the way I have to slip in one unrelated question to this thread, say I have a code:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
      float number;
      scanf("&#37;f", &number);
      printf("%f\n", number);
    
      return 0;
    }
    why doesn't it read directly from the command line when I typed in ./tiesto 0.5

    it doesn't print 0.5 directly but it goes as I haven't typed in anything but after I typed it in again underneath it works...

  5. #35
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,435
    scanf reads from the keyboard input, not the command line.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #36
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    well I thought I can do that.. in the previous assignment I have it works

  7. #37
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,435
    Doesn't work that way.
    You need to use a special main and get the arguments from there.
    There's a tutorial on the site maybe?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #38
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by -EquinoX- View Post
    well I thought I can do that.. in the previous assignment I have it works
    No it doesn't. You may have read arguments from argv[], but not using scanf.

  9. #39
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Code:
    #ifdef NO_WAI_64_BITS
    typedef int_8 something;
    #elif NO_WAI_32_BITS
    typedef int_4 something;
    #endif

  10. #40
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    oh nevermind it works if I did a redirect from a file.. okay back to our topic again.. the point to all of this is this.. I want main to create a message say that I run the program and defining that it's on 64 bit machine but however it's on a 32 bit machine.. then I want to be able to print this error:

    gcc -ansi -Wall -DMACHINE32 extract.c main.c -o main


    ERROR: sizeof(int_u8) is not 8, it's 4
    ERROR: sizeof(int_8) is not 8, it's 4

  11. #41
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,435
    I think you're on the wrong track here.
    The point of those typedefs is that uint64_t will always be 64-bit, whether or not it's a 32-bit machine or a 64-bit machine.
    Same goes for any other typedef.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #42
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    okay so the type def should all be the same either for 32 bit machine or 64 bit machine??

  13. #43
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,435
    The point is that if you use, for example, uint32_t, then
    sizeof(uint32_t) on a 32-bit machine will give 4
    and
    sizeof(uint32_t) on a 64-bit machine will give 4.

    The headers are full of #ifs and such to make sure this is the case.
    And of course, each compiler has its own such header to make sure it uses the correct type to make it's the right size when compiled.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #44
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The whole point with declaring typedefs (in this discussion) is that "you know what size the integer is". This helps in making sure for example that data structures are always the same size, data types match between different functions, etc.

    In many cases, a regular "int", whatever size it happens to be, is a fine thing to use, but sometimes you need a type that matches some specific size, such as "32 bits", and if you want to be SURE that the type is exactly 32 bits, then you need a typedef that depends on the compiler/processor architecture, etc.

    For example, a 64-bit compiler will make "long" a 64-bit number, but in a 32-bit compiler you need "long long" to make a 64-bit number.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Replies: 3
    Last Post: 05-13-2007, 08:55 AM
  4. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  5. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21