Thread: Variable without types and structures??

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    45

    Variable without types and structures??

    Hi,

    Code:
    struct List
    { long Data;
      List* Next;
      List()
      {Next=NULL;
       Data=0;
      }
    };
    Now in the aformentioned example, i have a few questions:
    long Data, there is no type what is it?, whats the purpose of putting long before it.
    The list() function is used to set the variables, is it called implicitly when the struct object instance is formed, or does it need to be explicitly called?

    Thanks
    Alex

  2. #2
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    long is a data type...
    You can't define any variables without types.

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    long (or long integer) is the type. It defines an integer of at least 32 bits of size. As such the variable Data is of type long.

    List is not a function. It is a struct. It is a user-defined type. A struct defines the data an object (on this case, List) contains and the operations it can perform.

    Check the tutorials for data types, structs and classes.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #4
    Registered User
    Join Date
    Aug 2006
    Posts
    45
    Quote Originally Posted by Mario F.
    long (or long integer) is the type. It defines an integer of at least 32 bits of size. As such the variable Data is of type long.

    List is not a function. It is a struct. It is a user-defined type. A struct defines the data an object (on this case, List) contains and the operations it can perform.

    Check the tutorials for data types, structs and classes.

    Ohh...god im dumb, so the list() is the constructor for the struct....
    So long is an integer that is 32bits, but you could have a long char, which is a char that is atleast 32bits long?

    Also if compiling on a 64bit machine, will these have a 64bit length when called long?

    Cheers
    Alex

  5. #5
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Not long char. But you do have wchar_t, known as wide char.

    Do not think of long as an adjective in C++. It is a noun. It does not define if a variable is bigger than another one by simply applying long to its definition as if an adjective it was. The only other built-in type with the word long is long double.

    Do check the tutorials on C++ variables and data types
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  6. #6
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Quote Originally Posted by Mario F.
    Not long char. But you do have wchar_t, known as wide char.

    Do not think of long as an adjective in C++. It is a noun. It does not define if a variable is bigger than another one by simply applying long to its definition as if an adjective it was. The only other built-in type with the word long is long double.

    Do check the tutorials on C++ variables and data types
    Actually 'long' does act a little like an adjective, and it's a quicker way of writing 'long int', although usually the 'int' is dropped (same as 'short int' becomes 'short'). However you are correct that you can't put long in front of any old type.

    The new C++ revision coming this decade will likely add 'long long' as a 64 bit or larger data type; it's already supported by many compilers and it's standard C, but not yet standard C++.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Structures, passing array of structures to function
    By saahmed in forum C Programming
    Replies: 10
    Last Post: 04-05-2006, 11:06 PM
  3. Custom variable types in C++
    By Aeroren in forum C++ Programming
    Replies: 2
    Last Post: 07-06-2005, 10:07 AM
  4. Replies: 2
    Last Post: 01-26-2003, 04:37 AM
  5. structures & data types
    By Cyber Kitten in forum C Programming
    Replies: 2
    Last Post: 11-07-2001, 07:07 AM