GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-Sep-2004, 08:22
soccer022483 soccer022483 is offline
New Member
 
Join Date: Mar 2004
Posts: 17
soccer022483 is on a distinguished road

What is unsigned?


I understand what unsigned is, like you can have an unsigned int, meaning not negative. But what does unsigned mean by itself? For example

unsigned x;

And is this bigger or smaller or equal to unsigned long? Which I understand is the biggest.

Thanks,
Austin
  #2  
Old 07-Sep-2004, 08:34
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 6,153
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by soccer022483
I understand what unsigned is, like you can have an unsigned int, meaning not negative. But what does unsigned mean by itself? For example

unsigned x;

And is this bigger or smaller or equal to unsigned long? Which I understand is the biggest.

Thanks,
Austin

It means the same as
CPP / C++ / C Code:
unsigned int x;

A long (same as a long int) must be at at least as big as an int (can be the same size, can be larger).

Try the following with your compiler:


CPP / C++ / C Code:
#include <stdio.h>

int main()
{
  char c;
  int i;
  long l;

  printf("sizeof(char) = %d, sizeof(c) = %d\n", sizeof(char), sizeof(c));
  printf("sizeof(int)  = %d, sizeof(i) = %d\n", sizeof(int), sizeof(i));
  printf("sizeof(long) = %d, sizeof(l) = %d\n", sizeof(long), sizeof(l));

  return 0;
}


Note that sizeof(char) is always 1 (that's in the C language standard). The others can be different with different compilers.

Some compilers have a "long long" that is longer than long. Not all have this.

Regards,

Dave
  #3  
Old 07-Sep-2004, 08:40
soccer022483 soccer022483 is offline
New Member
 
Join Date: Mar 2004
Posts: 17
soccer022483 is on a distinguished road
Quote:
Originally Posted by davekw7x
It means the same as
CPP / C++ / C Code:
unsigned int x;

A long (same as a long int) must be at at least as big as an int (can be the same size, can be larger).

Try the following with your compiler:


CPP / C++ / C Code:
#include <stdio.h>

int main()
{
  char c;
  int i;
  long l;

  printf("sizeof(char) = %d, sizeof(c) = %d\n", sizeof(char), sizeof(c));
  printf("sizeof(int)  = %d, sizeof(i) = %d\n", sizeof(int), sizeof(i));
  printf("sizeof(long) = %d, sizeof(l) = %d\n", sizeof(long), sizeof(l));

  return 0;
}


Note that sizeof(char) is always 1 (that's in the C language standard). The others can be different with different compilers.

Some compilers have a "long long" that is longer than long. Not all have this.

Regards,

Dave

What is the biggest I could use? I tried long double = 12 and long long = 8
  #4  
Old 07-Sep-2004, 08:52
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 6,153
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by soccer022483
What is the biggest I could use? I tried long double = 12 and long long = 8

What compiler? (and what Operating System?)

You don't get to pick the size, you take whatever it gives you for a given type.

Dave
  #5  
Old 07-Sep-2004, 09:00
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 6,153
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by davekw7x
What compiler? (and what Operating System?)

You don't get to pick the size, you take whatever it gives you for a given type.

Dave

Maybe I misunderstood. If you are getting sizeof(long long) = 8, and sizeof(long double) = 12, that's telling you how many bytes that variables of each type take up in memory.

It's telling you that:

long double is a floating point number that takes a total of 96 bits
long long is an integer with 64 bits

If they are there, you can use them any way you want to.

Regards,

Dave
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Encryption implementation issue bigbangman C Programming Language 6 02-Sep-2004 11:21
How to print unsigned __int64 israel_peter C Programming Language 2 02-Aug-2004 12:16
hashing help saiz66 C++ Forum 1 06-Jul-2004 06:16
(read/write file) newbie need help plz momotx C Programming Language 6 28-Jan-2004 13:40
convert long to pointer to char realpopeye C++ Forum 2 26-Sep-2003 10:22

Network Sites: GIDNetwork · GIDApp · GIDBlog · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:28.


vBulletin, Copyright © 2000 - 2014, Jelsoft Enterprises Ltd.