What's the difference between (size_t)-1 and ~0?What is the purpose of “int mask = ~0;”?Is static_cast<T>(-1) the right way to generate all-one-bits data without numeric_limits?What is the difference between -1 and ~0What is the difference between #include <filename> and #include “filename”?Signed versus Unsigned IntegersWhy doesn't C have unsigned floats?What is the difference between const int*, const int * const, and int const *?size_t vs. uintptr_tDifference between malloc and calloc?Improve INSERT-per-second performance of SQLite?Difference between signed / unsigned charshould use size_t or ssize_tWhy is unsigned integer overflow defined behavior but signed integer overflow isn't?
Who is "He that flies" in Lord of the Rings?
Why are MBA programs closing in the United States?
Adjusting in-line xy-pic diagrams to the baseline
Why isn't Bash trap working if output is redirected to stdout?
Is there a set of positive integers of density 1 which contains no infinite arithmetic progression?
The significance of kelvin as a unit of absolute temperature
Comparing arithmetic complexity of FFT radix-2 and convolution
Diatonic chords of a pentatonic vs blues scale?
Is it possible to have 2 different but equal size real number sets that have the same mean and standard deviation?
Can there be absolute velocity?
Transfer custom ringtones to iPhone using a computer running Linux
Do you have to have figures when playing D&D?
Confused with atmospheric pressure equals plastic balloon’s inner pressure
Why is Na5 not played in this line of the French Defense, Advance Variation?
Why Does Mama Coco Look Old After Going to the Other World?
Why do radiation hardened IC packages often have long leads?
Extracting data from Plot
Find the Missing Members of this Powered Sequence
Is using 'echo' to display attacker-controlled data on the terminal dangerous?
Latex - unable to get proper boxes
Use 1 9 6 2 in this order to make 75
Was planting UN flag on Moon ever discussed?
Analogy between an unknown in an argument, and a contradiction in the principle of explosion
Calculating the area of a parallelogram
What's the difference between (size_t)-1 and ~0?
What is the purpose of “int mask = ~0;”?Is static_cast<T>(-1) the right way to generate all-one-bits data without numeric_limits?What is the difference between -1 and ~0What is the difference between #include <filename> and #include “filename”?Signed versus Unsigned IntegersWhy doesn't C have unsigned floats?What is the difference between const int*, const int * const, and int const *?size_t vs. uintptr_tDifference between malloc and calloc?Improve INSERT-per-second performance of SQLite?Difference between signed / unsigned charshould use size_t or ssize_tWhy is unsigned integer overflow defined behavior but signed integer overflow isn't?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I've seen both (size_t)-1
and ~0
used to represent large numbers, or numbers with all their bits flipped.
Is there any difference between the two? If so, what is it?
I found this question: What is the difference between -1 and ~0, however it did not answer my question because I'm dealing with unsigned integers (such as size_t
), as opposed to signed integers (such as int
).
c unsigned ones-complement
add a comment |
I've seen both (size_t)-1
and ~0
used to represent large numbers, or numbers with all their bits flipped.
Is there any difference between the two? If so, what is it?
I found this question: What is the difference between -1 and ~0, however it did not answer my question because I'm dealing with unsigned integers (such as size_t
), as opposed to signed integers (such as int
).
c unsigned ones-complement
1
Note that~0
is a signed quantity — you'd need~0U
to make it unsigned.
– Jonathan Leffler
Apr 14 at 18:56
Should I edit that?
– JL2210
Apr 14 at 18:58
3
Since you've got some answers which addresses~0
rather than~0U
, best to leave it unchanged, I think, but note for the future that it is a good idea to be careful. You can change a question up until making the change would invalidate answers.
– Jonathan Leffler
Apr 14 at 19:05
related: Is static_cast<T>(-1) the right way to generate all-one-bits data without numeric_limits?, What is the purpose of "int mask = ~0;"?
– phuclv
Apr 15 at 1:47
Differences: First is C++. Second is not unsigned.
– JL2210
Apr 15 at 11:03
add a comment |
I've seen both (size_t)-1
and ~0
used to represent large numbers, or numbers with all their bits flipped.
Is there any difference between the two? If so, what is it?
I found this question: What is the difference between -1 and ~0, however it did not answer my question because I'm dealing with unsigned integers (such as size_t
), as opposed to signed integers (such as int
).
c unsigned ones-complement
I've seen both (size_t)-1
and ~0
used to represent large numbers, or numbers with all their bits flipped.
Is there any difference between the two? If so, what is it?
I found this question: What is the difference between -1 and ~0, however it did not answer my question because I'm dealing with unsigned integers (such as size_t
), as opposed to signed integers (such as int
).
c unsigned ones-complement
c unsigned ones-complement
asked Apr 14 at 18:50
JL2210JL2210
1,439726
1,439726
1
Note that~0
is a signed quantity — you'd need~0U
to make it unsigned.
– Jonathan Leffler
Apr 14 at 18:56
Should I edit that?
– JL2210
Apr 14 at 18:58
3
Since you've got some answers which addresses~0
rather than~0U
, best to leave it unchanged, I think, but note for the future that it is a good idea to be careful. You can change a question up until making the change would invalidate answers.
– Jonathan Leffler
Apr 14 at 19:05
related: Is static_cast<T>(-1) the right way to generate all-one-bits data without numeric_limits?, What is the purpose of "int mask = ~0;"?
– phuclv
Apr 15 at 1:47
Differences: First is C++. Second is not unsigned.
– JL2210
Apr 15 at 11:03
add a comment |
1
Note that~0
is a signed quantity — you'd need~0U
to make it unsigned.
– Jonathan Leffler
Apr 14 at 18:56
Should I edit that?
– JL2210
Apr 14 at 18:58
3
Since you've got some answers which addresses~0
rather than~0U
, best to leave it unchanged, I think, but note for the future that it is a good idea to be careful. You can change a question up until making the change would invalidate answers.
– Jonathan Leffler
Apr 14 at 19:05
related: Is static_cast<T>(-1) the right way to generate all-one-bits data without numeric_limits?, What is the purpose of "int mask = ~0;"?
– phuclv
Apr 15 at 1:47
Differences: First is C++. Second is not unsigned.
– JL2210
Apr 15 at 11:03
1
1
Note that
~0
is a signed quantity — you'd need ~0U
to make it unsigned.– Jonathan Leffler
Apr 14 at 18:56
Note that
~0
is a signed quantity — you'd need ~0U
to make it unsigned.– Jonathan Leffler
Apr 14 at 18:56
Should I edit that?
– JL2210
Apr 14 at 18:58
Should I edit that?
– JL2210
Apr 14 at 18:58
3
3
Since you've got some answers which addresses
~0
rather than ~0U
, best to leave it unchanged, I think, but note for the future that it is a good idea to be careful. You can change a question up until making the change would invalidate answers.– Jonathan Leffler
Apr 14 at 19:05
Since you've got some answers which addresses
~0
rather than ~0U
, best to leave it unchanged, I think, but note for the future that it is a good idea to be careful. You can change a question up until making the change would invalidate answers.– Jonathan Leffler
Apr 14 at 19:05
related: Is static_cast<T>(-1) the right way to generate all-one-bits data without numeric_limits?, What is the purpose of "int mask = ~0;"?
– phuclv
Apr 15 at 1:47
related: Is static_cast<T>(-1) the right way to generate all-one-bits data without numeric_limits?, What is the purpose of "int mask = ~0;"?
– phuclv
Apr 15 at 1:47
Differences: First is C++. Second is not unsigned.
– JL2210
Apr 15 at 11:03
Differences: First is C++. Second is not unsigned.
– JL2210
Apr 15 at 11:03
add a comment |
3 Answers
3
active
oldest
votes
What's the difference between (size_t)-1 and ~0?
Type and value differ.
(size_t)-1
is the same value as SIZE_MAX
and has a type of size_t
.
~0
is often -1 and has the type of int
.
Assigning both of those to a size_t
will result in SIZE_MAX
.
size_t a = (size_t)-1;
size_t b = ~0;
In the 2nd case, -1
is assigned to a b
and undergoes a conversion first, wrapping around the -1 to the maximum size_t
value.
Comments are not for extended discussion; this conversation has been moved to chat.
– Bhargav Rao♦
Apr 14 at 19:51
add a comment |
(size_t)-1
is of type size_t
. It typically has a value of 232-1 or 264-1 (4294967295
or 18446744073709551615
).
~0
is of type int
, and has the value -1
on a 2's-complement system (i.e., just about everywhere).
Both are likely to have the same bit pattern -- if int
and size_t
are the same size, which they very commonly are not.
If you want the maximum value of type size_t
, you can use the SIZE_MAX
macro, defined in <stdint.h>
. If you're using an older implementation (pre-C99) that doesn't provide SIZE_MAX
, (size_t)-1
will work. I'm not sure why you'd want to write ~0
rather than -1
-- unless perhaps you're considering non-two's-complement systems.
Thanks for letting me know. I'll remember to defineSIZE_MAX
in mystdint.h
implementation.
– JL2210
Apr 14 at 19:02
Re;~0
versus-1
- some compilers warn on implicit wrapping in constant expressions.
– TLW
Apr 14 at 21:43
add a comment |
Note that the previous answers assume a 2's complement machine (very likely to be the case these days, but not guaranteed).
If you had a sign-magnitude machine then -1
would have a sign bit and least significant bit set with all others clear, if you had a 1's complement machine then -1
would have all bits but the LSB set.
In all of these cases (including the common 2's complement machine), ~0
has all bits set.
Note that in the question I'm asking about unsigned integers, so there's no such thing as a "sign bit".
– JL2210
Apr 14 at 20:56
2
@JL2210 - note that the intermediate values of both~0
and-1
are signed, not unsigned.
– TLW
Apr 14 at 21:41
Ah. I understand now. I'll upvote as soon as this is edited.
– JL2210
Apr 14 at 22:02
Concerning non-2s-complement: The most recent non-2's complement machine I have heard of was from somewhere in 2000-2008 and I have not used one since pre-1990. Do you know of any in use in the last 10 years?
– chux
Apr 15 at 0:54
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55678835%2fwhats-the-difference-between-size-t-1-and-0%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
What's the difference between (size_t)-1 and ~0?
Type and value differ.
(size_t)-1
is the same value as SIZE_MAX
and has a type of size_t
.
~0
is often -1 and has the type of int
.
Assigning both of those to a size_t
will result in SIZE_MAX
.
size_t a = (size_t)-1;
size_t b = ~0;
In the 2nd case, -1
is assigned to a b
and undergoes a conversion first, wrapping around the -1 to the maximum size_t
value.
Comments are not for extended discussion; this conversation has been moved to chat.
– Bhargav Rao♦
Apr 14 at 19:51
add a comment |
What's the difference between (size_t)-1 and ~0?
Type and value differ.
(size_t)-1
is the same value as SIZE_MAX
and has a type of size_t
.
~0
is often -1 and has the type of int
.
Assigning both of those to a size_t
will result in SIZE_MAX
.
size_t a = (size_t)-1;
size_t b = ~0;
In the 2nd case, -1
is assigned to a b
and undergoes a conversion first, wrapping around the -1 to the maximum size_t
value.
Comments are not for extended discussion; this conversation has been moved to chat.
– Bhargav Rao♦
Apr 14 at 19:51
add a comment |
What's the difference between (size_t)-1 and ~0?
Type and value differ.
(size_t)-1
is the same value as SIZE_MAX
and has a type of size_t
.
~0
is often -1 and has the type of int
.
Assigning both of those to a size_t
will result in SIZE_MAX
.
size_t a = (size_t)-1;
size_t b = ~0;
In the 2nd case, -1
is assigned to a b
and undergoes a conversion first, wrapping around the -1 to the maximum size_t
value.
What's the difference between (size_t)-1 and ~0?
Type and value differ.
(size_t)-1
is the same value as SIZE_MAX
and has a type of size_t
.
~0
is often -1 and has the type of int
.
Assigning both of those to a size_t
will result in SIZE_MAX
.
size_t a = (size_t)-1;
size_t b = ~0;
In the 2nd case, -1
is assigned to a b
and undergoes a conversion first, wrapping around the -1 to the maximum size_t
value.
edited Apr 14 at 19:10
answered Apr 14 at 18:56
chuxchux
86.5k875160
86.5k875160
Comments are not for extended discussion; this conversation has been moved to chat.
– Bhargav Rao♦
Apr 14 at 19:51
add a comment |
Comments are not for extended discussion; this conversation has been moved to chat.
– Bhargav Rao♦
Apr 14 at 19:51
Comments are not for extended discussion; this conversation has been moved to chat.
– Bhargav Rao♦
Apr 14 at 19:51
Comments are not for extended discussion; this conversation has been moved to chat.
– Bhargav Rao♦
Apr 14 at 19:51
add a comment |
(size_t)-1
is of type size_t
. It typically has a value of 232-1 or 264-1 (4294967295
or 18446744073709551615
).
~0
is of type int
, and has the value -1
on a 2's-complement system (i.e., just about everywhere).
Both are likely to have the same bit pattern -- if int
and size_t
are the same size, which they very commonly are not.
If you want the maximum value of type size_t
, you can use the SIZE_MAX
macro, defined in <stdint.h>
. If you're using an older implementation (pre-C99) that doesn't provide SIZE_MAX
, (size_t)-1
will work. I'm not sure why you'd want to write ~0
rather than -1
-- unless perhaps you're considering non-two's-complement systems.
Thanks for letting me know. I'll remember to defineSIZE_MAX
in mystdint.h
implementation.
– JL2210
Apr 14 at 19:02
Re;~0
versus-1
- some compilers warn on implicit wrapping in constant expressions.
– TLW
Apr 14 at 21:43
add a comment |
(size_t)-1
is of type size_t
. It typically has a value of 232-1 or 264-1 (4294967295
or 18446744073709551615
).
~0
is of type int
, and has the value -1
on a 2's-complement system (i.e., just about everywhere).
Both are likely to have the same bit pattern -- if int
and size_t
are the same size, which they very commonly are not.
If you want the maximum value of type size_t
, you can use the SIZE_MAX
macro, defined in <stdint.h>
. If you're using an older implementation (pre-C99) that doesn't provide SIZE_MAX
, (size_t)-1
will work. I'm not sure why you'd want to write ~0
rather than -1
-- unless perhaps you're considering non-two's-complement systems.
Thanks for letting me know. I'll remember to defineSIZE_MAX
in mystdint.h
implementation.
– JL2210
Apr 14 at 19:02
Re;~0
versus-1
- some compilers warn on implicit wrapping in constant expressions.
– TLW
Apr 14 at 21:43
add a comment |
(size_t)-1
is of type size_t
. It typically has a value of 232-1 or 264-1 (4294967295
or 18446744073709551615
).
~0
is of type int
, and has the value -1
on a 2's-complement system (i.e., just about everywhere).
Both are likely to have the same bit pattern -- if int
and size_t
are the same size, which they very commonly are not.
If you want the maximum value of type size_t
, you can use the SIZE_MAX
macro, defined in <stdint.h>
. If you're using an older implementation (pre-C99) that doesn't provide SIZE_MAX
, (size_t)-1
will work. I'm not sure why you'd want to write ~0
rather than -1
-- unless perhaps you're considering non-two's-complement systems.
(size_t)-1
is of type size_t
. It typically has a value of 232-1 or 264-1 (4294967295
or 18446744073709551615
).
~0
is of type int
, and has the value -1
on a 2's-complement system (i.e., just about everywhere).
Both are likely to have the same bit pattern -- if int
and size_t
are the same size, which they very commonly are not.
If you want the maximum value of type size_t
, you can use the SIZE_MAX
macro, defined in <stdint.h>
. If you're using an older implementation (pre-C99) that doesn't provide SIZE_MAX
, (size_t)-1
will work. I'm not sure why you'd want to write ~0
rather than -1
-- unless perhaps you're considering non-two's-complement systems.
edited Apr 14 at 19:01
Jonathan Leffler
582k966961052
582k966961052
answered Apr 14 at 19:00
Keith ThompsonKeith Thompson
197k27292490
197k27292490
Thanks for letting me know. I'll remember to defineSIZE_MAX
in mystdint.h
implementation.
– JL2210
Apr 14 at 19:02
Re;~0
versus-1
- some compilers warn on implicit wrapping in constant expressions.
– TLW
Apr 14 at 21:43
add a comment |
Thanks for letting me know. I'll remember to defineSIZE_MAX
in mystdint.h
implementation.
– JL2210
Apr 14 at 19:02
Re;~0
versus-1
- some compilers warn on implicit wrapping in constant expressions.
– TLW
Apr 14 at 21:43
Thanks for letting me know. I'll remember to define
SIZE_MAX
in my stdint.h
implementation.– JL2210
Apr 14 at 19:02
Thanks for letting me know. I'll remember to define
SIZE_MAX
in my stdint.h
implementation.– JL2210
Apr 14 at 19:02
Re;
~0
versus -1
- some compilers warn on implicit wrapping in constant expressions.– TLW
Apr 14 at 21:43
Re;
~0
versus -1
- some compilers warn on implicit wrapping in constant expressions.– TLW
Apr 14 at 21:43
add a comment |
Note that the previous answers assume a 2's complement machine (very likely to be the case these days, but not guaranteed).
If you had a sign-magnitude machine then -1
would have a sign bit and least significant bit set with all others clear, if you had a 1's complement machine then -1
would have all bits but the LSB set.
In all of these cases (including the common 2's complement machine), ~0
has all bits set.
Note that in the question I'm asking about unsigned integers, so there's no such thing as a "sign bit".
– JL2210
Apr 14 at 20:56
2
@JL2210 - note that the intermediate values of both~0
and-1
are signed, not unsigned.
– TLW
Apr 14 at 21:41
Ah. I understand now. I'll upvote as soon as this is edited.
– JL2210
Apr 14 at 22:02
Concerning non-2s-complement: The most recent non-2's complement machine I have heard of was from somewhere in 2000-2008 and I have not used one since pre-1990. Do you know of any in use in the last 10 years?
– chux
Apr 15 at 0:54
add a comment |
Note that the previous answers assume a 2's complement machine (very likely to be the case these days, but not guaranteed).
If you had a sign-magnitude machine then -1
would have a sign bit and least significant bit set with all others clear, if you had a 1's complement machine then -1
would have all bits but the LSB set.
In all of these cases (including the common 2's complement machine), ~0
has all bits set.
Note that in the question I'm asking about unsigned integers, so there's no such thing as a "sign bit".
– JL2210
Apr 14 at 20:56
2
@JL2210 - note that the intermediate values of both~0
and-1
are signed, not unsigned.
– TLW
Apr 14 at 21:41
Ah. I understand now. I'll upvote as soon as this is edited.
– JL2210
Apr 14 at 22:02
Concerning non-2s-complement: The most recent non-2's complement machine I have heard of was from somewhere in 2000-2008 and I have not used one since pre-1990. Do you know of any in use in the last 10 years?
– chux
Apr 15 at 0:54
add a comment |
Note that the previous answers assume a 2's complement machine (very likely to be the case these days, but not guaranteed).
If you had a sign-magnitude machine then -1
would have a sign bit and least significant bit set with all others clear, if you had a 1's complement machine then -1
would have all bits but the LSB set.
In all of these cases (including the common 2's complement machine), ~0
has all bits set.
Note that the previous answers assume a 2's complement machine (very likely to be the case these days, but not guaranteed).
If you had a sign-magnitude machine then -1
would have a sign bit and least significant bit set with all others clear, if you had a 1's complement machine then -1
would have all bits but the LSB set.
In all of these cases (including the common 2's complement machine), ~0
has all bits set.
edited Apr 15 at 0:22
JL2210
1,439726
1,439726
answered Apr 14 at 20:39
SoronelHaetirSoronelHaetir
7,4911514
7,4911514
Note that in the question I'm asking about unsigned integers, so there's no such thing as a "sign bit".
– JL2210
Apr 14 at 20:56
2
@JL2210 - note that the intermediate values of both~0
and-1
are signed, not unsigned.
– TLW
Apr 14 at 21:41
Ah. I understand now. I'll upvote as soon as this is edited.
– JL2210
Apr 14 at 22:02
Concerning non-2s-complement: The most recent non-2's complement machine I have heard of was from somewhere in 2000-2008 and I have not used one since pre-1990. Do you know of any in use in the last 10 years?
– chux
Apr 15 at 0:54
add a comment |
Note that in the question I'm asking about unsigned integers, so there's no such thing as a "sign bit".
– JL2210
Apr 14 at 20:56
2
@JL2210 - note that the intermediate values of both~0
and-1
are signed, not unsigned.
– TLW
Apr 14 at 21:41
Ah. I understand now. I'll upvote as soon as this is edited.
– JL2210
Apr 14 at 22:02
Concerning non-2s-complement: The most recent non-2's complement machine I have heard of was from somewhere in 2000-2008 and I have not used one since pre-1990. Do you know of any in use in the last 10 years?
– chux
Apr 15 at 0:54
Note that in the question I'm asking about unsigned integers, so there's no such thing as a "sign bit".
– JL2210
Apr 14 at 20:56
Note that in the question I'm asking about unsigned integers, so there's no such thing as a "sign bit".
– JL2210
Apr 14 at 20:56
2
2
@JL2210 - note that the intermediate values of both
~0
and -1
are signed, not unsigned.– TLW
Apr 14 at 21:41
@JL2210 - note that the intermediate values of both
~0
and -1
are signed, not unsigned.– TLW
Apr 14 at 21:41
Ah. I understand now. I'll upvote as soon as this is edited.
– JL2210
Apr 14 at 22:02
Ah. I understand now. I'll upvote as soon as this is edited.
– JL2210
Apr 14 at 22:02
Concerning non-2s-complement: The most recent non-2's complement machine I have heard of was from somewhere in 2000-2008 and I have not used one since pre-1990. Do you know of any in use in the last 10 years?
– chux
Apr 15 at 0:54
Concerning non-2s-complement: The most recent non-2's complement machine I have heard of was from somewhere in 2000-2008 and I have not used one since pre-1990. Do you know of any in use in the last 10 years?
– chux
Apr 15 at 0:54
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55678835%2fwhats-the-difference-between-size-t-1-and-0%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Note that
~0
is a signed quantity — you'd need~0U
to make it unsigned.– Jonathan Leffler
Apr 14 at 18:56
Should I edit that?
– JL2210
Apr 14 at 18:58
3
Since you've got some answers which addresses
~0
rather than~0U
, best to leave it unchanged, I think, but note for the future that it is a good idea to be careful. You can change a question up until making the change would invalidate answers.– Jonathan Leffler
Apr 14 at 19:05
related: Is static_cast<T>(-1) the right way to generate all-one-bits data without numeric_limits?, What is the purpose of "int mask = ~0;"?
– phuclv
Apr 15 at 1:47
Differences: First is C++. Second is not unsigned.
– JL2210
Apr 15 at 11:03