Thread: Howto assign an address to an integer variable

  1. #16
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    To me it looks like the address of string can be hold as a number
    It just looks this way. Because you are using compiler where this two types have the same size

    There are compilers where these two types will be of the different size
    That's why standard complient compiler will always warn about such a cast
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Addresses are treated as pointers in C, which is the whole reason it doesn't work without a cast.
    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.

  3. #18
    Registered User
    Join Date
    Feb 2008
    Posts
    30
    Thanks guys

    It is clear to me now.

    Regards,

    Ben

  4. #19
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by daYz View Post
    That is why I still don't understand why this would not work:

    Code:
    int x = string;
    To me it looks like the address of string can be hold as a number by the integer variable.

    Thanks
    Yeah but what if the code had been this:

    Code:
    char x = (char)string;
    A char is only a single byte. And this will compile fine, because it uses a cast. But a byte is obviously not enough to hold a pointer value. Unless you are working on an 8-bit system that has 256 bytes of memory :P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  2. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM
  3. Im so lost at . .
    By hermit in forum C Programming
    Replies: 18
    Last Post: 05-15-2002, 01:26 AM
  4. pointerz
    By xlordt in forum C Programming
    Replies: 6
    Last Post: 01-11-2002, 08:31 PM
  5. Variable Allocation in a simple operating system
    By awkeller in forum C Programming
    Replies: 1
    Last Post: 12-08-2001, 02:26 PM