Thread: constants of long

  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
    Chappell Hill, Texas
    Posts
    2,332
    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.
    Mainframe assembler programmer by trade. C coder when I can.

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, 12: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, 12:30 PM