size and range of int in c

C

cfaqs c

The range of int is (2 to the power of 8 - 1) to (2 to the power of
8), which requires just 1 byte.
Whereas the size of an integer is 4 bytes.... using sizeof(int).

Why then are 3 extra bytes?
 
S

Seebs

The range of int is (2 to the power of 8 - 1) to (2 to the power of
8), which requires just 1 byte.

No it isn't. The range of int is no less than (-32767,32767)...
Whereas the size of an integer is 4 bytes.... using sizeof(int).

Not necessariily.
Why then are 3 extra bytes?

There aren't.

If your machine has 4-byte ints, the chances are pretty good that the
range of int on your system is a bit over +/- 2 billion (2^31).

-s
 
C

cfaqs c

No it isn't.  The range of int is no less than (-32767,32767)...


Not necessariily.


There aren't.

If your machine has 4-byte ints, the chances are pretty good that the
range of int on your system is a bit over +/- 2 billion (2^31).

-s

If the size is 4 bytes, how is a small number, say 6, stored in the
machine. 6 in binary is 110. So all the prefix bits in the 4 bytes of
storage is padded with zero is it?

Also, how is a negative number stored? I mean i want to know it's
binary representation
 
S

Seebs

If the size is 4 bytes, how is a small number, say 6, stored in the
machine. 6 in binary is 110. So all the prefix bits in the 4 bytes of
storage is padded with zero is it?

It's not padding, it's part of the representation of the number. But yes,
it's all 4 bytes. You can't change the size on the fly. (There are
languages in which you can, but that's sort of different.)
Also, how is a negative number stored? I mean i want to know it's
binary representation

It depends on your system. Different systems do it differently. The
most common systems are called "1s complement", "2s complement", and
"sign/magnitude.

The risk you face here is that you seem to be trying much too hard to
"figure out what really happens" -- if you do that really early on, it's
easy to get stuck on expecting every computer you ever encounter to be just
like the one you learned on, and since that's not likely to be the case,
it can screw you over badly.

Start out by being aware that these answers may change sometimes, and it'll
be less likely to bite you badly later.

-s
 
S

spinoza1111

No it isn't.  The range of int is no less than (-32767,32767)...

Yes, which is just as bad as old Visual Basic. In VB 3.0 you had to
code around "integers" restricted to this range and strings whose
length was similarly restricted.

So C is a usable language for safe programming how?
Not necessariily.

That constitutes a flaw in C. "C integer" does not, in fact, have a
definite meaning, whereas "integer" has a definition in a modern and
safe language such as C Sharp.
There aren't.

If your machine has 4-byte ints, the chances are pretty good that the
range of int on your system is a bit over +/- 2 billion (2^31).

If he is using twos complement like a normal person the range can be
known: it is -2^31..2^31-1. This isn't in the Standard. It should be.
 
S

spinoza1111

It's not padding, it's part of the representation of the number.  But yes,
it's all 4 bytes.  You can't change the size on the fly.  (There are
languages in which you can, but that's sort of different.)


It depends on your system.  Different systems do it differently.  The
most common systems are called "1s complement", "2s complement", and
"sign/magnitude.

The risk you face here is that you seem to be trying much too hard to
"figure out what really happens" -- if you do that really early on, it's

He needs to know constructively (as in Mathematical intuitionism) what
really happens and may be trusted like a normal person to generalize
his experience UNLESS he is socialised to do things by rote &
shibboleth.
easy to get stuck on expecting every computer you ever encounter to be just
like the one you learned on, and since that's not likely to be the case,

Actually, programmers who aren't socialized by corporate fear can
intuit that the computer, like a geometrical diagram, has essential
and accidental features, for the same reason intelligent students in
geometry class don't worry about the thickness of the lines they have
drawn using straightedge and compass in geometrical construction.

The problem, of course, is two fold.

First of all, students no longer are taught geometry axiomatically
since their teachers generally are more trained in paperwork and fear
than in axiomatic reasoning. Instead, they are taught to compete for
rewards through rote & shibboleth.

They never get to the point to which they can be led by a competent
teacher at which they see that a sloppy diagram with thick lines is
functionally equivalent to a precise diagram. Quite the opposite, for
teachers who are themselves ignorant of geometry take points off for
sloppiness, neatness being a shibboleth or password just as here,
yapping about main() is a shibboleth.

I knew starting in January 1970, four months prior to the invasion of
Cambodia, that the IBM 1401 was radically different from the IBM 7094.
Stop patronizing the OP.
it can screw you over badly.

Start out by being aware that these answers may change sometimes, and it'll
be less likely to bite you badly later.

If you presume to instruct him at all, you yourself need to know some
modal logic, in particular how to distunguish necessity from accident.
You didn't bother to take compsci. I might forgive you for posing as
an authority if you took modal logic, but don't bet on it.
 
R

Richard Tobin

cfaqs c said:
The range of int is (2 to the power of 8 - 1) to (2 to the power of
8), which requires just 1 byte.

That would require just one bit :)

-- Richard
 
A

Aatu Koskensilta

spinoza1111 said:
He needs to know constructively (as in Mathematical intuitionism) what
really happens and may be trusted like a normal person to generalize
his experience UNLESS he is socialised to do things by rote &
shibboleth.

This allusion to intuitionism is somewhat obscure. Perhaps you can
elaborate on what you have in mind?
 
S

spinoza1111

This allusion to intuitionism is somewhat obscure. Perhaps you can
elaborate on what you have in mind?

Intuitionism is the insistence that we do math without the excluded
middle and proceed by constructing proofs from what we know. It
refuses to posit entities which we know "must" exist by way of
excluded middle but which we can't construct.

[Some variants of intuitionism go to unwarranted extremes: I read an
article in the Journal of Symbolic Logic in 1972 which seemed to claim
that "big" numbers such as 100 factorial don't exist in the same way
small numbers exist: my response was to write an assembler program for
the old IBM 1401 to calculate the precise value of 100 factorial. It
was actually easy to do so without simulating extra precision because
the 1401 had a "variable length word".]

Applied to programming, intuitionism would insist that a program must
be constructed bug-free before we can say we know that one exists. And
whether the "program" is constructed using a programming language, or
using mathematical symbols as a written intuitionist proof, it is
going to have essences (meaning) and accidents (notation or an actual
automaton which is either a real computer or an abstract, but fully
described, automaton such as a Turing machine).

What Seebach claims implies that in formal automata, the professor
CANNOT draw a Turing machine on the board and explain that this shows
what computers do, since the professor's constructive proof (proof by
construction) is "only" a picture, and it might confuse the students,
who MIGHT think that on the job they will have to program Turing
machines.

Which is nonsense, and grievously insulting to professors, their
students, and education.
 
S

spinoza1111

This allusion to intuitionism is somewhat obscure. Perhaps you can
elaborate on what you have in mind?

Intuitionism is the insistence that we do math without the excluded
middle and proceed by constructing proofs from what we know. It
refuses to posit entities which we know "must" exist by way of
excluded middle but which we can't construct.

[Some variants of intuitionism go to unwarranted extremes: I read an
article in the Journal of Symbolic Logic in 1972 which seemed to claim
that "big" numbers such as 100 factorial don't exist in the same way
small numbers exist: my response was to write an assembler program for
the old IBM 1401 to calculate the precise value of 100 factorial. It
was actually easy to do so without simulating extra precision because
the 1401 had a "variable length word".]

Applied to programming, intuitionism would insist that a program must
be constructed bug-free before we can say we know that one exists. And
whether the "program" is constructed using a programming language, or
using mathematical symbols as a written intuitionist proof, it is
going to have essences (meaning) and accidents (notation or an actual
automaton which is either a real computer or an abstract, but fully
described, automaton such as a Turing machine).

What Seebach claims implies that in formal automata, the professor
CANNOT draw a Turing machine on the board and explain that this shows
what computers do, since the professor's constructive proof (proof by
construction) is "only" a picture, and it might confuse the students,
who MIGHT think that on the job they will have to program Turing
machines.

Which is nonsense, and grievously insulting to professors, their
students, and education.




"Wovon man nicht sprechen kann, darüber muss man schweigen"
 - Ludwig Wittgenstein, Tractatus Logico-Philosophicus- Hide quoted text -

- Show quoted text -

It is however true that Dijkstra, who I consider an intuitionist at
heart, didn't like reasoning with images and claimed (EWD375) to have
discovered a generalization of the Pythagorean theorem to oblique
triangles using symbolic reasoning exclusively. Nonetheless, he was an
intuitionist in the moral sense of refusing to acknowledge that a bug-
free program could exist without some sort of correctness
proof...often one from which he could derive the code of the program.
 
E

Eric Sosman

cfaqs said:
The range of int is (2 to the power of 8 - 1) to (2 to the power of
8), which requires just 1 byte.

The range you mention has just two values (or possibly
128), so one bit (seven bits) is enough.

However (as others have pointed out), the range of `int'
is wider than you suppose. For example, an `int' can store
negative values, which your range{,s} exclude{s,}.
 
N

Nick

spinoza1111 said:
Yes, which is just as bad as old Visual Basic. In VB 3.0 you had to
code around "integers" restricted to this range and strings whose
length was similarly restricted.

So C is a usable language for safe programming how?

In the light of that last sentence I think it's time, for the fourth
time of asking, to ask "is English your native language".

Before you return to preaching about the meaning of "clarity" to the
rest of us, I wonder if you could explain the paragraph above.

You seem to be suggesting that any machine with finite length integers
is "bad", Is that it?
 
J

John Kelly

In the light of that last sentence I think it's time, for the fourth
time of asking, to ask "is English your native language".

I don't know the answer to that question. But it's apparent that his
vocabulary and command of the language are greater than a majority of
native English speakers.

What would you conclude if you knew his native language?
 
S

Seebs

This allusion to intuitionism is somewhat obscure. Perhaps you can
elaborate on what you have in mind?

It seems unlikely. He is not much good at elaborating or explaining.

Spinny's just mad that people who learn about the abstract machine rather
than a real machine seem to be better able to keep code running, and thus
stay employed. The idea that it might be possible to learn from this
experience seems foreign.

-s
 
S

Seebs

I don't know the answer to that question. But it's apparent that his
vocabulary and command of the language are greater than a majority of
native English speakers.

Strictly speaking, probably true, but the mistakes he makes are absolutely
fascinating.

-s
 
R

Richard Bos

Aatu Koskensilta said:
This allusion to intuitionism is somewhat obscure. Perhaps you can
elaborate on what you have in mind?

*Bzzt* Assumption of presence of object without evidence thereof.

Richard
 
D

Dik T. Winter

>
> If he is using twos complement like a normal person the range can be
> known: it is -2^31..2^31-1. This isn't in the Standard. It should be.

So they should have instantly obsoleted the Gould computers? Are you
proposing a situation where a single provider of computers mandates how
everything is done?

Darn, a standards mandated monopoly...
 
D

Dik T. Winter

> He needs to know constructively (as in Mathematical intuitionism) what
> really happens and may be trusted like a normal person to generalize
> his experience UNLESS he is socialised to do things by rote &
> shibboleth.

Interesting that you again bring in something you know nothing about. In
this case intuitionism. Try once to read the works by Brouwer and
acknowledge that you are spouting nonsense. Intuitionism is about a way
to *prove* something, not about generalisations. Most mathematical
generalisations are not valid in intuitionism because there is no
constructive proof.
> Actually, programmers who aren't socialized by corporate fear can
> intuit that the computer, like a geometrical diagram, has essential
> and accidental features, for the same reason intelligent students in
> geometry class don't worry about the thickness of the lines they have
> drawn using straightedge and compass in geometrical construction.

That is indeed the way trisection proofs are worked out. Sheesh, can you
not get anything right?
 
S

spinoza1111

It seems unlikely.  He is not much good at elaborating or explaining.

Spinny's just mad that people who learn about the abstract machine rather
than a real machine seem to be better able to keep code running, and thus
stay employed.  The idea that it might be possible to learn from this
experience seems foreign.

Don't confuse me with the anxious fearful you that rages behind the
mask. My point was that there's no such thing as the "abstract
machine" that one doesn't see through a glass darkly. The compsci
student, which you weren't, is equally apt to be deluded by the Turing
Machine as the DeVry student by the IBM PC, since both models have
essential and accidental features. You've adopted anti-PCism as a
fashion statement but don't have the proper background to start viral
attacks on people such as Schildt.
 
S

spinoza1111

...
 > > If your machine has 4-byte ints, the chances are pretty good that the
 > > range of int on your system is a bit over +/- 2 billion (2^31).
 >
 > If he is using twos complement like a normal person the range can be
 > known: it is -2^31..2^31-1. This isn't in the Standard. It should be..

So they should have instantly obsoleted the Gould computers?  Are you
proposing a situation where a single provider of computers mandates how
everything is done?

Yes. A tremendous amount of time has been wasted in useless
"competition" that would have been better spent meeting real human
needs such as clean water and education.
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top