Thread: long values

  1. #1
    Registered User daluu's Avatar
    Join Date
    Dec 2002
    Posts
    42

    long values

    I'm not very familiar with long values, other than it being a form of numbers like integers, so:

    is the long value 2L equate to simply 2 base type long, or something more?

    if so then wouldn't this be the same:

    Code:
    long var;
    
    var = 2L;
    var = 2; //same thing?

  2. #2
    Registered User daluu's Avatar
    Join Date
    Dec 2002
    Posts
    42
    i see there are a number of page views. why hasn't anyone responded?

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Some differences would be noticeable on a platform that has different sized ints and longs when the constant is used in an expression.
    Code:
    #include <stdio.h>
    
    int main(void)
    {
       long a = 32000 * 4, b = 32000 * 4L, c = 32000L * 4, d = 32000L * 4L, e;
       printf("sizeof(2)  = %lu\n", (long unsigned)sizeof(2));
       printf("sizeof(2L) = %lu\n", (long unsigned)sizeof(2L));
       printf("a = %ld, b = %ld, c = %ld, d = %ld\n", a, b, c, d);
       e = 1  << 16; printf("e = %ld\n", e);
       e = 1L << 16; printf("e = %ld\n", e);
       return 0;
    }
    
    /* my output
    sizeof(2)  = 2
    sizeof(2L) = 4
    a = -3072, b = 128000, c = 128000, d = 128000
    e = 0
    e = 65536
    */
    >i see there are a number of page views. why hasn't anyone responded?

    Don't do this (see #5).
    Last edited by Dave_Sinkula; 05-09-2003 at 12:31 PM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Registered User daluu's Avatar
    Join Date
    Dec 2002
    Posts
    42
    thanks. ;-)

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by daluu
    i see there are a number of page views. why hasn't anyone responded?
    Probably because we're not your personal servents.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. hton long long
    By carrotcake1029 in forum C Programming
    Replies: 1
    Last Post: 06-01-2008, 08:26 PM
  3. Need help with project
    By chrisa777 in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2006, 05:01 PM
  4. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 08:55 AM
  5. How do i un-SHA1 hash something..
    By willc0de4food in forum C Programming
    Replies: 4
    Last Post: 09-14-2005, 05:59 AM