![]() |
|
#1
|
|||
|
|||
How to tell a type is signed or unsigned?CPP / C++ / C Code:
Suppose I have mytype that could be defined as either signed (int, short, long) or unsigned. And I don't know what the type is passed in. How do I tell if mytype is a signed type or not? Last edited by LuciWiz : 09-May-2008 at 08:15.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|
|||
|
#2
|
|||
|
|||
Re: How to tell a type is signed or unsigned?You could set it to a negative value, then read it and see if it is still negative.
|
|
#3
|
|||
|
|||
Re: How to tell a type is signed or unsigned?Quote:
If you declare that mytype is an int, the function treats it as an int. If you declare that mytype is an unsigned int, the function treats it as an unsigned int. If the calling program has an argument that is not the same type as the declared function, the compiler converts it if necessary. Note that casting an int to an unsigned int (or vice versa) doesn't actually change the bits stored in memory, but that's irrelevant to your question: the function just gets a value from the calling program and the parameter type (inside the function) is defined by the function declaration. CPP / C++ / C Code:
Output Code:
Regards, Dave Last edited by davekw7x : 05-May-2008 at 09:49.
|
Recent GIDBlog
Programming ebook direct download available by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| BMP image on matrix load | nemo | C++ Forum | 21 | 18-Dec-2007 00:04 |
| Linker Error | athika_32 | C Programming Language | 6 | 03-Dec-2007 08:38 |
| [Linker error] undefined reference to `WinMain@16' | squid | C++ Forum | 5 | 02-Mar-2007 23:58 |
| Hard drive/CPU Diagnoses Issues | binarybug | Computer Hardware Forum | 1 | 22-Jan-2007 20:23 |
| fltk-2.0 cvs | Plumb | FLTK Forum | 20 | 13-Nov-2004 08:10 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The