sizeof~

This is a discussion on sizeof~ within the C++ Programming forums, part of the General Programming Boards category; Hi, all~ Something result by sizeof method is 1, could that only contain 1 byte thing ?...

  1. #1
    flashing vampire black's Avatar
    Join Date
    May 2002
    Posts
    563

    sizeof~

    Hi, all~

    Something result by sizeof method is 1, could that only contain 1 byte thing ?
    Last edited by black; 08-05-2002 at 06:26 AM.
    Never end on learning~

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    The sizeof operator always returns the size of the variable in BYTES (not for dynamic or external arrays). So yes, it means the size is 1 byte.

  3. #3
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330
    Yeah... booleans and characters are single bytes.

  4. #4
    Registered User toaster's Avatar
    Join Date
    Apr 2002
    Posts
    161
    shouldn't bools be by bits rahter than by bytes (waste of memory)?

    ---

    now ever used a nibble yet?
    think only with code.
    write only with source.

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by rmullen3
    Yeah... booleans and characters are single bytes.
    Depends on what machine you are on. On intels booleans take up 4 bytes. You can use a character (1 byte) to store 8 booleans as toaster mentioned with the bits comment. You just have to remember which bits corresponds to which flag. Then just do some simple bit manipulation to check and set them.

  6. #6
    flashing vampire black's Avatar
    Join Date
    May 2002
    Posts
    563
    Originally posted by MrWizard


    Depends on what machine you are on. On intels booleans take up 4 bytes. You can use a character (1 byte) to store 8 booleans as toaster mentioned with the bits comment. You just have to remember which bits corresponds to which flag. Then just do some simple bit manipulation to check and set them.
    yep. And I just figure out my compiler could accept this line:
    PHP Code:
    char x;
    x='abcd';
    cout << << endl
    Only the output show a single 'd'.
    Never end on learning~

  7. #7
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by black


    yep. And I just figure out my compiler could accept this line:
    PHP Code:
    char x;
    x='abcd';
    cout << << endl
    Only the output show a single 'd'.
    thats the way its supposed to be of course
    hello, internet!

Popular pages Recent additions subscribe to a feed

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