constants of long

This is a discussion on constants of long within the C++ Programming forums, part of the General Programming Boards category; I read that one should always suffix long constants with L. So whats the difference between the following two examples: ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    330

    constants of long

    I read that one should always suffix long constants with L.

    So whats the difference between the following two examples:

    Code:
    long x = 100L; // no L
    x = x * 2L; // no L

    Code:
    long x = 100; // no L
    x = x * 2; // no L
    I dont see what the problem could ever be with the second form

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    To start, depending on your machine, there may or may not be a difference between int and long. If there is no difference, then this conversation is a moot point.

    If there is a difference between int and long on your machine, then that's the difference, and long would use 8 bytes to hold a value and int would use 4.

    For all practical purposes, for your example, since x is defined as long, the end result is the same.

    To see any differences, you would need to view the generated assembler source, and be able to understand assembler, to see the difference.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting using pointer to pointer not working
    By eager2no in forum C Programming
    Replies: 17
    Last Post: 09-21-2008, 01:52 AM
  2. Having Buffer Problems With Overlapped I/O --
    By Sargera in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 04:46 PM
  3. Problem in Converting Unsigned long to String
    By cprogrammer_18 in forum C Programming
    Replies: 8
    Last Post: 01-14-2006, 08:57 AM
  4. Dev-cpp - compiler options
    By tretton in forum C Programming
    Replies: 7
    Last Post: 01-06-2006, 06:20 PM
  5. Insertion Sort Problem
    By silicon in forum C++ Programming
    Replies: 1
    Last Post: 05-08-2005, 01:30 PM

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