C compiler question (I hope this is on topic)

S

Seebs

Given the following...
#include <stdio.h>
int main(void)
{
char x;
x = 5;
return 0;
}

How does the object know that the value 5 of type char at run time if
the type is discarded after compile time?

You have omitted some words here or something. Your question can be
rephrased as:
If the type is discarded after compile time, then:
How does the object know that the value 5 of type char at run time?

Which can be reduced to:
How does the object know that the value 5 of type char at run time?

"the value 5 of type char" is a noun. You could replace it with a name,
like "Betty", and then we have:
How does the object know that Betty at run time?

"Betty" is a noun, but "know that" needs a description like, say, a noun
and a verb. Or perhaps you meant:
How does the object know that the value 5 *is* of type char at run time?

The value 5 is not of type char, it's of type int. It is then converted
to char and stored in an object x. Nothing anywhere ever has to know that
the value 5 is of type char, because it isn't. All that's happening is
that the compiler generates code which manipulates a char object; the code
generated is different, probably, than the code that would be generated for
an int or a long. There is no knowledge of types at run time; there's only
the objects and the actions upon them.

-s
 
C

Chad

Given the following...

#include <stdio.h>

int main(void)
{
char x;
x = 5;

return 0;
}

How does the object know that the value 5 of type char at run time if
the type is discarded after compile time?
 
I

Ian Collins

Given the following...

#include<stdio.h>

int main(void)
{
char x;
x = 5;

return 0;
}

How does the object know that the value 5 of type char at run time if
the type is discarded after compile time?

The type isn't discarded at compile time, it is in the generated machine
code. For example a processor may have different op codes to move and
manipulate different sized operands (say movb for bytes and movw for
words and movl for double words).
 
K

Keith Thompson

Ian Collins said:
The type isn't discarded at compile time, it is in the generated machine
code. For example a processor may have different op codes to move and
manipulate different sized operands (say movb for bytes and movw for
words and movl for double words).

Well, sort of. Some information about the type is implicit in the
generated machine code, but the type itself is not represented and
may not be determinable.

For example, this:
int x = 5;
and this:
long y = 5;
may result in identical machine code if int and long happen to have
the same size.

As Seebs pointed out, the constant 5 is of type int. The rules of
the language say that, in an assignment, the RHS (right hand side)
expression is evaluated and the result is *converted* to the type
of the LHS and then copied.

So, at least conceptually, the int value 5 is converted from int
to char, and then the result of the conversion is stored in x.
All the information about what expression is of what type and what
conversions and other operations are required is determined at
compile time, when all the type information is still available.

In practice, the conversion from int to char is likely not to
show in the generated code; depending on the target architecture,
there might be a single move-byte instruction with a literal 5 as
its source and the address of x as its target. As long as the final
result is the same, the compiler may collapse multiple operations
into something simpler.
 
C

Chad

You have omitted some words here or something.  Your question can be
rephrased as:


Which can be reduced to:


"the value 5 of type char" is a noun.  You could replace it with a name,
like "Betty", and then we have:


"Betty" is a noun, but "know that" needs a description like, say, a noun
and a verb.  Or perhaps you meant:


The value 5 is not of type char, it's of type int.  It is then converted
to char and stored in an object x.  Nothing anywhere ever has to know that
the value 5 is of type char, because it isn't.  All that's happening is
that the compiler generates code which manipulates a char object; the code
generated is different, probably, than the code that would be generated for
an int or a long.  There is no knowledge of types at run time; there's only
the objects and the actions upon them.

I think I've mentioned before that grammar is not one of my strong
points. I never got above a D in any of my High School English
classes. And yes, I actually was trying.
 
S

spinoza1111

I think I've mentioned before that grammar is not one of my strong
points. I never got above a D in any of my High School English
classes. And yes, I actually was trying.

Good answers. Pity that the regs here are willing to give good answers
to guys named Chad, but not Shamir or Wen Tzu.
 
J

jacob navia

Chad a écrit :
Given the following...

#include <stdio.h>

int main(void)
{
char x;
x = 5;

return 0;
}

How does the object know that the value 5 of type char at run time if
the type is discarded after compile time?

The object doesn't know anything, nor the computer.
Only people can know something, and this, I know:

The compiler takes the text of your program, and translates it into
an equivalent that, when run in an appropiated printed circuit like the
computer that is running in your box, would produce the same effects you
specified in the input program.

In your program you specified:

"Put the value of 5 in a local variable of type char"

char x;
x = 5;

If you take a compiler like lcc-win for instance, you will see that the following instructions are
generated from your program:

.line 4
; 5 char x;
; 6 x = 5;
.line 6
movb $5,-1(%ebp)

The compiler generated a move byte instruction (movb) with the
immediate value of 5 to a memory location at 1 byte less than the value
contained in the frame pointer EBP.

In the prologue of the function, the compiler reserved several
byte locations that can contain the values of the local variables.
The place at -1 (%ebp) is reserved for your character
variable "x".

Then, the compiler generated an instruction that will move 5 into it.

Very simple, and neither the computer, nor the variable, nor anything
"knows" what they are doing, in the same sense that your car doesn't
really know where it is going: it is YOU that knows where YOU are going
and you instruct the car to go there (you "drive" it).

You drive a computer by telling it step by step where it should go. The
computer (like a car) doesn't KNOW anything, and if you tell it to
do nonsense it will do it with the same lack of resistence that your
car will accept that you drive it into a wall without ever complaining
about it.

People have a different kind of circuit than a computer. People know
things, people are even able to build circuits: we are the first circuit
that is able to build circuits. Computers and other circuits that WE build
aren't able to reproduce or do anything without OUR circuit to guide
them, they are MACHINES.

Besides being unable to know something, machines are made out of parts.
You can take your car or your computer apart, then rebuild it, and they
will go on working as before. Our circuit however, can't be taken apart
like that. If you try to take it apart it will stop working and
decompose immediately, instead of working for a few years still as other
circuits that aren't taken apart do.

Still, if you go to the basics of our circuit, the brain, we see that
many of its parts are "machine like". For instance we have an interpreter
called "ribosome", that reads our source code and interprets each codon
into proteins at roughly 50-60 codons per minute. It takes single stranded
source code in one side, and outputs fully folded proteins/enzymes, whatever
that is specified in the source code using 20 building blocks called
amino-acids.

The ribosome is made out of two parts, and if you take them apart and then
rebuild the original ribosome again, the newly built ribosome will go on working
as before, like a machine.

Does the ribosome KNOW what it is doing?

Does the ribosome understand the codons it is interpreting?

Unlikely since it doesn't realize when it introduces an error. If it
misreads a codon and puts the wrong amino-acid in the sequence of the
protein it is building it will produce the wrong output.

In the same vein we have a text editor, for instance. It is BECAUSE
your text editor that you are still alive. Even if the copying mechanism
of your source code is very faithfull, sometimes it does make mistakes

Those mistakes would accumulate if there wasn't for your friend the text
editor that proof reads the copy of the source code and corrects the errors
the copying mechanism introduced.

Does the text editor KNOW the text?

Well, a modern text editor will underscore in red any word that is not
in the dictionary. Somehow our text editor knows about the syntax of
the source code and is able to diagnose a wrong copy, mark it as wrong
and call the repair enzymes to fix the typos.

But then, what is KNOWING???

Does your text editor KNOW english when it says that "ariund" is wrong and
it should be "around" instead?

No. Knowing english would mean that you can WRITE english text and that you
use it to communicate with your peer circuits hanging around in comp.lang.c.

(Even if you aren't very strong in grammar, as you say, I wouldn't doubt that
you KNOW english).

So, to KNOW what it is doing, the text editor would have to produce NEW
source code, i.e. new features of the circuit it is specifying.

But in time frames of millions of years we see that NEW features appear,
without any doubt.

Six million years ago, there wasn't any circuit like the one you have in your
head. It is a COMPLETELY NEW circuit, that nature had NEVER invented till...
well, till 6 million years ago.

Was it the text editor that wrote the new code?

Because there IS new code in our source code. True, we share a lot of source
code with the monkeys and other animals, but there is a tiny but very
significant portion of our source code that is COMPLETELY NEW.

One of the measures of instability of source code is the number of
repeated copies of whole genes.

You know. You are writing a new specialization of some software, you
copy and paste a routine and start hacking around.

Well, "nature" does the same. In species where a rapid evolution is happening,
a LOT of genes are duplicated genes with some modifications, where you can
"see" the hacker writing new code. And, as you would expect, humans are
champions in the number of duplicated genes they have.

Another proof that we are evolving rapidly.

But WHO is writing the NEW code???

The text editor?

Is the text editor rearranging our source code, tinkering with it?

Or is it something ELSE?

WHO KNOWS WHAT IS GOING ON?

How does the character "x" know that it should have 5 as value?

Well, my answer is:

Because the system's driver DESIGNED the system that way for his OWN
purposes that the poor character "x" doesn't have the slightest idea.

Neither the character "x", that exists for a fleeting microsecond
and receives its value to disappear instantly afterwards, (the main program
reaching its last statement right afterwards) nor the computer where it
is running, that will be able to run several billions of similar programs
before he, too, is discarded by the user and thrown away at the
discharge of old computers.

No, neither the character "x" nor the computer know anything. They are
just instantiations of a program, designed by you.

But YOU TOO, you are going to reach your end statement sooner or later,
as you well KNOW, to the contrary of character"x" and his computer home.

And surely, as anything else in the universe the writer of the human program
will ALSO reach its end statement someday... Yes, it will be
probably in a billion years from now, when the aging sun will start
expanding into its red giant phase and will evaporate all oceans of this earth
eliminating all life from its surface.

Then, the writer will disappear, together with its creations.

And the sun too, after its red giant phase, will explode and
disappear from view, leaving a white cinder star, follwoed by
some giant planets, wandering aimlessly in the eternal darkness.

But in a fleeting micro-second THERE WAS a character "x" that
received its value because for a fleeting century there
was a circuit that built circuits because he liked that. And he
liked that maybe because he was programmed to, by the unknown
and invisible hacker that wanted for some unknown purpose in this
world full of ignorance a being that built circuits and asked
himself:

WHAT DO *I* KNOW?

WHERE ARE WE GOING?

WHERE DO WE CAME FROM?


Yours sincerely

jacob
 
B

bart.c

Chad said:
Given the following...

#include <stdio.h>

int main(void)
{
char x;
x = 5;

return 0;
}

How does the object know that the value 5 of type char at run time if
the type is discarded after compile time?

char is just another integer type, which typically range from 1 to 8 bytes,
and can be signed or unsigned.

There is nothing special about the 'char' designation.

And where the 'type' of x (ie. it's width and signedness, which is all that
C cares about) is relevant in the runtime code , then this is represented
implicitly in the code produced.
 
T

Tim Streater

[snip]
Good answers. Pity that the regs here are willing to give good answers
to guys named Chad, but not Shamir or Wen Tzu.

If Shamir or Wen Tzu were to actually post here, I expect they would. As
a reg yourself, you could too.
 
N

Nick Keighley

Chad a écrit :





The object doesn't know anything, nor the computer.
Only people can know something, and this, I know:

"know" is being used to mean "holds information about". Even if we
accept that humans "know" in a different sense from computers I'm not
convinced that other animals "know" in our sense. I also think "know"
in the human sense is only slightly more complicated taht "know" in
the computer sense. We just can't disentagle the representaion at this
point.

Very simple, and neither the computer, nor the variable, nor anything
"knows" what they are doing, in the same sense that your car doesn't
really know where it is going: it is YOU that knows where YOU are going
and you instruct the car to go there (you "drive" it).

there are cars now that can drive themselves and solve simple route
planning problems. Eventually "knowing" boils down to the
representation of knowledge.
You drive a computer by telling it step by step where it should go.

generally not. The gulf between the user and the hardware is so vast
now it is hardly meaningful to talk about step-by-step.

People have a different kind of circuit than a computer.

as a materilaist I can't agree with this. You're smuggling vitalism in
by the back door. The human brain is still a physical object as
constained by the laws of physics as a silicon chip.
People know
things, people are even able to build circuits: we are the first circuit
that is able to build circuits. Computers and other circuits that WE build
aren't able to reproduce or do anything without OUR circuit to guide
them, they are MACHINES.

so are we
Besides being unable to know something, machines are made out of parts.
You can take your car or your computer apart, then rebuild it, and they
will go on working as before. Our circuit however, can't be taken apart
like that. If you try to take it apart it will stop working and
decompose immediately, instead of working for a few years still as other
circuits that aren't taken apart do.

brain surgery. Try patching the CPU chip in your computer and see how
it does.

<snip>

But in time frames of millions of years we see that NEW features appear,
without any doubt.

Six million years ago, there wasn't any circuit like the one you have in your
head. It is a COMPLETELY NEW circuit, that nature had NEVER invented till....
well, till 6 million years ago.

Was it the text editor that wrote the new code?

Because there IS new code in our source code. True, we share a lot of source
code with the monkeys and other animals, but there is a tiny but very
significant portion of our source code that is COMPLETELY NEW.

One of the measures of instability of source code is the number of
repeated copies of whole genes.

You know. You are writing a new specialization of some software, you
copy and paste a routine and start hacking around.

Well, "nature" does the same. In species where a rapid evolution is happening,
a LOT of genes are duplicated genes with some modifications, where you can
"see" the hacker writing new code. And, as you would expect, humans are
champions in the number of duplicated genes they have.

really? I didn't know this. Do you have a cite?

Another proof that we are evolving rapidly.

I wasn't aware that we were

But WHO is writing the NEW code???

evolution. There is no "who".

And surely, as anything else in the universe the writer of the human program
will ALSO reach its end statement someday... Yes, it will be
probably in a billion years from now, when the aging sun will start
expanding into its red giant phase and will evaporate all oceans of this earth
eliminating all life from its surface.

you actually think we'll last that long?

Then, the writer will disappear, together with its creations.

And the sun too, after its red giant phase, will explode and
disappear from view,


the sun is too small to "explode"
leaving a white cinder star, follwoed by
some giant planets, wandering aimlessly in the eternal darkness.

But in a fleeting micro-second THERE WAS a character "x" that
received its value because for a fleeting century there
was a circuit that built circuits because he liked that. And he
liked that maybe because he was programmed to, by  the unknown
and invisible hacker that wanted for some unknown purpose in this
world full of ignorance a being that built circuits and asked
himself:

there is no invisible hacker
 
N

Nick Keighley

But in a fleeting micro-second THERE WAS a character "x" that
received its value because for a fleeting century there
was a circuit that built circuits because he liked that. And he
liked that maybe because he was programmed to, by  the unknown
and invisible hacker that wanted for some unknown purpose in this
world full of ignorance a being that built circuits [...]

Je n'ai pas besoin de cette hypothèse.
Pierre-Simon Laplace
 
K

Kenny McCormack

[snip]
Good answers. Pity that the regs here are willing to give good answers
to guys named Chad, but not Shamir or Wen Tzu.

If Shamir or Wen Tzu were to actually post here, I expect they would. As
a reg yourself, you could too.

Liar. You know perfectly well that (in CLC) "reg" is a term of art. It
is *not* simply shorthand for "one who posts frequently".

You know that.

(Channelling Kiki) "You've been told this several times."

--
(This discussion group is about C, ...)

Wrong. It is only OCCASIONALLY a discussion group
about C; mostly, like most "discussion" groups, it is
off-topic Rorsharch [sic] revelations of the childhood
traumas of the participants...
 
J

jacob navia

Nick Keighley a écrit :
really? I didn't know this. Do you have a cite?

http://www.plosbiology.org/article/info:doi/10.1371/journal.pbio.0020236

Great Ape Genomes Offer Insight into Human Evolution.

<quote>
One of the primary agents of genome evolution is gene duplication.
Duplicated genes provide the raw material for the generation of novel
genes and biological functions, which in turn allow the evolution of
organismal complexity and new species. (For more on duplicated genes,
see the primer by Hurles in this issue.) James Sikela and colleagues set
out to compare gene duplications between humans and four of our closest
primate relatives to find the genetic roots of our evolutionary split
from the other great apes. Collecting the DNA of humans, chimpanzees,
bonobos, gorillas, and orangutans from blood and experimental cell
lines, the researchers used microarray analysis to identify variations
in the number of copies of individual genes among the different species.
They analyzed nearly 30,000 human genes and compared their copy numbers
in the genomes of humans and the four great apes.

Overall, Sikela and colleagues found more than 1,000 genes with
lineage-specific changes in copy number, representing 3.4% of the genes
tested. All the great ape species showed more increases than decreases
in gene copy numbers, but relative to the evolutionary age of each
lineage, humans showed the highest number of genes with increased copy
numbers, at 134. Many of these duplicated human genes are implicated in
brain structure and function.
<end quote>
 
S

Seebs

If Shamir or Wen Tzu were to actually post here, I expect they would. As
a reg yourself, you could too.

I am unwilling to give "good" answers to the fakeposts/trolls/idiots from
IUT because they don't respond in any way to queries. It has nothing to
do with their names, and everything to do with the contents of their posts.

-s
 
N

Nick Keighley

"know" is being used to mean "holds information about". Even if we
accept that humans "know" in a different sense from computers I'm not
convinced that other animals "know" in our sense.

zzzzzt!! There's a negation missing there somewhere. "I'm not
convinced that other animals DON'T "know" in our sense". Some of the
higher apes seem to think in a similar fashion to us (if only on
simpler problems).


<snip>
 
N

Nick Keighley

Nick Keighley a écrit :









http://www.plosbiology.org/article/info:doi/10.1371/journal.pbio.0020236

Great Ape Genomes Offer Insight into Human Evolution.

<quote>
One of the primary agents of genome evolution is gene duplication.
Duplicated genes provide the raw material for the generation of novel
genes and biological functions, which in turn allow the evolution of
organismal complexity and new species. (For more on duplicated genes,
see the primer by Hurles in this issue.) James Sikela and colleagues set
out to compare gene duplications between humans and four of our closest
primate relatives to find the genetic roots of our evolutionary split
from the other great apes. Collecting the DNA of humans, chimpanzees,
bonobos, gorillas, and orangutans from blood and experimental cell
lines, the researchers used microarray analysis to identify variations
in the number of copies of individual genes among the different species.
They analyzed nearly 30,000 human genes and compared their copy numbers
in the genomes of humans and the four great apes.

Overall, Sikela and colleagues found more than 1,000 genes with
lineage-specific changes in copy number, representing 3.4% of the genes
tested. All the great ape species showed more increases than decreases
in gene copy numbers, but relative to the evolutionary age of each
lineage, humans showed the highest number of genes with increased copy
numbers, at 134. Many of these duplicated human genes are implicated in
brain structure and function.
<end quote>

thanks, it doesn't explicitly say we are evolving faster than the
other great apes (though it does prety well imply it). It also doesn't
say how our gene duplication rates compare with anything apart from
great apes. Mice may evolve faster than us.
 
S

spinoza1111

I am unwilling to give "good" answers to the fakeposts/trolls/idiots from
IUT because they don't respond in any way to queries.  It has nothing to
do with their names, and everything to do with the contents of their posts.

The questions are good. They don't owe you a reply. Furthermore, based
on your attack on Schildt and lack of qualifications or compensatory
competence, we do not think you are in a position to judge.

The people from IUT are attacked because they have Islamic names.
Likewise, posters from mainland China are insulted because of their
English.
 
T

Tim Streater

spinoza1111 said:
The questions are good. They don't owe you a reply.

And he doesn't owe them a reply either.
The people from IUT are attacked because they have Islamic names.
Likewise, posters from mainland China are insulted because of their
English.

Which Chinese posters is that, then?

Keep your racist slurs to yourself.
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top