Let's talk about datatypes

Discussion in 'Programming General' started by Faskist, Feb 5, 2008.

Let's talk about datatypes
  1. Unread #1 - Feb 5, 2008 at 7:03 PM
  2. Faskist
    Joined:
    Apr 25, 2005
    Posts:
    1,869
    Referrals:
    0
    Sythe Gold:
    0

    Faskist Tuxhead
    Banned

    Let's talk about datatypes

    So, this morning, I wrote a simple program to sate my curiosity (Such is all hacking) about something I'd never bothered to find out -- just how big is the memory allocated to the datatypes we use everyday?

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
      int i;
    
      i = sizeof(char);
      
      printf( "A char is this big: |" );
      while( i > 0)
        {
          printf( "-" );
          --i;
        }
      printf( "|\n" );
      
      i = sizeof(int);
      
      printf( "An int is this big: |" );
      while( i > 0)
        {
          printf( "-" );
          --i;
        }
      printf( "|\n" );
      
      i = sizeof(short);
      
      printf( "A short is this big: |" );
      while( i > 0)
        {
          printf( "-" );
          --i;
        }
      printf( "|\n" );
      
      i = sizeof(long);
      
      printf( "A long is this big: |" );
      while( i > 0)
        {
          printf( "-" );
          --i;
        }
      printf( "|\n" );
      
      return 0;
    }
    I know the code seriously needs refactoring, and it could be cleaned up so much, but I just wanted a quick solution.

    The answer you'll get depends on platform, but in mine... int is as big as long!! The horror! The bloat!
     
  3. Unread #2 - Feb 6, 2008 at 9:45 AM
  4. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    Let's talk about datatypes

    That's because with your compiler (and mine) integers and longs are able to take on the same values (-2147483648 to 2147483647). The more common integer we're used to (-32768 to 32767) is changed to be called short int.

    [​IMG]
     
  5. Unread #3 - Feb 6, 2008 at 8:04 PM
  6. Faskist
    Joined:
    Apr 25, 2005
    Posts:
    1,869
    Referrals:
    0
    Sythe Gold:
    0

    Faskist Tuxhead
    Banned

    Let's talk about datatypes

    That's so redundant, lol. How does I changed long to 8 bytes?
     
  7. Unread #4 - Feb 6, 2008 at 9:32 PM
  8. Govind
    Joined:
    Apr 22, 2005
    Posts:
    7,825
    Referrals:
    13
    Sythe Gold:
    23
    Prove it! Trole Tier 1 Prizebox Tortoise Penis Le Monkey UWotM8? Wait, do you not have an Archer rank? Potamus

    Govind The One Musketeer
    Mudkips Highly Respected Retired Administrator

    Let's talk about datatypes

    __int64?
     
  9. Unread #5 - Feb 6, 2008 at 9:40 PM
  10. Cruel__Machine
    Referrals:
    100

    Cruel__Machine Guest

    Let's talk about datatypes

    Yup, int = long.

    I at least prefer this to VB making Integer = Short. So I always accidentally use Integer instead of Long. Or I used to at least, I don't use VB much these days.

    I know how to do 64bit math with 32bit registers. At least I used to... it's all kind of blurry... I haven't used asm in like a year. :'(
     
  11. Unread #6 - Feb 7, 2008 at 2:30 AM
  12. Sythe
    Joined:
    Apr 21, 2005
    Posts:
    8,071
    Referrals:
    467
    Sythe Gold:
    5,281
    Discord Unique ID:
    742989175824842802
    Discord Username:
    Sythe
    Dolan Duck Dolan Trump Supporting Business ???
    Poképedia
    Clefairy Jigglypuff
    Who did this to my freakin' car!
    Hell yeah boooi
    Tier 3 Prizebox Toast Wallet User
    I'm LAAAAAAAME Rust Player Mewtwo Mew Live Free or Die Poké Prizebox (42) Dat Boi

    Sythe Join our discord

    test

    Administrator Village Drunk

    Let's talk about datatypes

    Of course an int is the same size as a long. Both are 32 bit full words on x86.

    Incidentally, that code is incredibly roundabout. All you needed was one printf:

     
  13. Unread #7 - Feb 7, 2008 at 6:21 AM
  14. Faskist
    Joined:
    Apr 25, 2005
    Posts:
    1,869
    Referrals:
    0
    Sythe Gold:
    0

    Faskist Tuxhead
    Banned

    Let's talk about datatypes

    I actually wrote some code very similar to that when discussing it on a textboard, but my code produces a nice pretty (almost) graphical representation of it (And could still be improved and refactored).
     
< Vb Runescape Webbrowser question | NeedleHaystack FindImage Method >

Users viewing this thread
1 guest


 
 
Adblock breaks this site