S
Stefan Strasser
although I don't agree that's a reason to use signed in interfaces:
http://www.aristeia.com/Papers/C++ReportColumns/sep95.pdf
http://www.aristeia.com/Papers/C++ReportColumns/sep95.pdf
I don't know of any reason why it would make a speed difference, but it
is not there just for backwards compatibility by any stretch of
imagination.
Remember that the types are different sizes. Have data that can range
up to, say, 4 billion but you can gurantee will be positive? You gotta
use an unsigned int.
[QUOTE="Julie said:Hey
Lots of functions return 0 - N for okay and -1 for error
conditions.
msalters said:No, use unsigned long.
unsigned int is guaranteed to be non-negative, but it may be as small
as 16 bits. long has to be 32 bits.
Michael said:No. §3.9.1 says:
3. For each of the signed integer types, there exists a corresponding
(but different) unsigned integer rype: "unsigned char", "unsigned short
int", "unsigned int", and "unsigned long int," each of which occupies
the same amount of storage and has the same alignment requirements (3.9)
as the corresponding signed integer type; [...]
And now let's see to the signed integer types:
2. There are four signed integer types: "signed char", "short int",
"int", and "long int". In this list, each type provides at least as much
storage as those preceding it in the list. Plain ints have the natural
size suggested by the architecture of the execurtion environment (that
is, large enough to contain any value in the range of INT_MIN and
INT_MAX, as defined in the header <climits>); the other signed integer
types are provided to meet special needs.
You see that the amount of storage of long is just as inexact as that of
int.
msalters said:No, use unsigned long.
unsigned int is guaranteed to be non-negative, but it may be as small
as 16 bits. long has to be 32 bits.
No. §3.9.1 says:
[snip]
Plain ints have the natural size suggested by the architecture of the
execurtion environment (that is, large enough to contain any value in
the range of INT_MIN and INT_MAX, as defined in the header <climits>);
the other signed integer types are provided to meet special needs.
You see that the amount of storage of long is just as inexact as that of
int.
Ioannis said:There is the guarantee that signed and unsigned:
short and int can hold at least 16 bit integer values, long at least
32-bit values and char at least 8-bit values.
Richard said:You won't be in favour of using the STL, then.
std::find returns the "end" iterator if it can't find a match.
string functions return npos. And so on.
I don't see how cluttering the interface with an extra returned value
would help matters, and failure to find a match isn't usually the kind
of unexpected event that exceptions were intended to handle.
[QUOTE="Julie said:You won't be in favour of using the STL, then.
std::find returns the "end" iterator if it can't find a match.
string functions return npos. And so on.
I don't see how cluttering the interface with an extra returned
value would help matters, and failure to find a match isn't usually
the kind of unexpected event that exceptions were intended to handle.
'Not found' and similar are not errors, but indicators.
Song said:an unsigned int could be better used to represent a bigger range of
positive integers (obviously 0-2^32, assuming a 32 bit platform),
whereas an int can only represent up to 2^31 positive integers. So if I
know that a number is always going to be a positive integer, I feel like
I'm wasting some "range".
The same reason you would use a char instead of a short int etc.
Richard said:So, I suspect, was the OP, despite his use of the word "error".
Indeed, but they still use a special "value" to indicate something that
isn't a value at all. Is that an indication of poor design?
Julie said:On the whole, and off-topic here, I think that the /language/ is
severely deficient in its parameter input and return value handling.
Single-return-value functions are far too limiting, and [out] parameters
just lead to clutter, language hacks (pointers/references), etc. Again,
not topical here.
Ioannis said:Julie said:On the whole, and off-topic here, I think that the /language/ is
severely deficient in its parameter input and return value handling.
Single-return-value functions are far too limiting, and [out]
parameters just lead to clutter, language hacks (pointers/references),
etc. Again, not topical here.
I think you should check the std:air as a return value.
Julie said:Any structure can be returned from a function, but then you must cache
that value (i.e. new variable) or just use a single field.
Again, my ideas aren't topical here, but I think that C/C++ parameter
handling is so 1960's.
What about being really revolutionary and returning a special sentinelIoannis Vranos said:What about returning pointers for run-time/space expensive values?
Ioannis said:What about returning pointers for run-time/space expensive values?
Julie said:Again, a hack for a language deficiency.
Maybe it is time that I design my own language.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.