Thread: SizeOf function

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    15

    Question SizeOf function

    Hi everyone, i'm just starting out with C, and i'm not too sure how to use the SizeOf Function, I need to use it to verify that an inputted integer is not greater than the maximun number of bytes allowed....and i don't know how to do this...i've done this:
    if ((sizeof(digit) > 655536) || (digit==NULL))
    printf("ERROR: That is too large an integer");

    but I know that's wrong cuz i get this msg:

    getData.c:12: warning: comparison between pointer and integer

    if you could help me I'd be so greatful,
    thanks eveyone!
    from Mel

  2. #2
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >>and i'm not too sure how to use the SizeOf Function, I need to use it to verify that an inputted integer is not greater than the maximun number of bytes allowed
    First things first, sizeof isn't a function, it's an operator :-) And it returns the number of bytes of the object you pass to it, not the maximum value that can be held by those bytes. So your problem could be solved like this
    Code:
    #include <stdio.h>
    
    int main(void)
    {
      if (sizeof(int) > 2)
        /* Only allow the minimum integer size */
      {
        fprintf(stderr, "Fatal error: Integer size too large\n");
      }
    
      return 0;
    }
    *Cela*

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    15

    Re:

    would that still work in my function?
    cuz I dont' want to put that in my main method



    I tried, what you said, and now I get this warning

    getData.c:14: warning: passing arg 1 of `printf' from incompatible pointer type
    thanks eveyone!
    from Mel

  4. #4
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >>would that still work in my function?
    Sure, just paste it into your function and you're set :-)

    >>getData.c:14: warning: passing arg 1 of `printf' from incompatible pointer type
    It looks like you're trying to use printf with fprintf arguments. fprintf takes an output stream as it's first argument, try changing it to
    Code:
    printf("Fatal error: Integer size too large\n");
    *Cela*

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    15

    thanks!

    thanks a lot for your help!
    thanks eveyone!
    from Mel

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 08:55 AM
  3. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM