473,395 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

new question about old C compiler

I guess this is new, at least to people who don't know about this, like
me, please be prepared to give me a satifying answer,
so please tell me how the compiler "knows" variable "i" as in a
declaration of "int i" is of type "int"?

Jul 17 '06 #1
4 1292
On Mon, 16 Jul 2006, Today's Mulan wrote:
I guess this is new, at least to people who don't know about this, like
me, please be prepared to give me a satifying answer,
so please tell me how the compiler "knows" variable "i" as in a
declaration of "int i" is of type "int"?
Er, because you told the compiler so ? You know, like in "int i;" ? Thus,
until the end of the current lexical scope, "i" is bound to be of type
"int".

--
"Je deteste les ordinateurs : ils font toujours ce que je dis, jamais ce
que je veux !"
"The obvious mathematical breakthrough would be development of an easy
way to factor large prime numbers." (Bill Gates, The Road Ahead)
Jul 17 '06 #2
On 16 Jul 2006 17:28:30 -0700, "Today's Mulan"
<to*********@slidemail.comwrote:
>I guess this is new, at least to people who don't know about this, like
me, please be prepared to give me a satifying answer,
so please tell me how the compiler "knows" variable "i" as in a
declaration of "int i" is of type "int"?
There is nothing magical about i. The compiler doesn't know anything
about i until you tell it. In the case you cite, the compiler
recognizes the keyword int and applies that meaning the object name
that follows. If you had written "double i;", i would be a double and
not an int.

What is your real question?

Are you trying to learn how to write a compiler?

Are you trying to understand how your compiler parses the code?
(If so, the answer is it depends on the compiler.)
Remove del for email
Jul 17 '06 #3

Barry Schwarz のメッセージ:
On 16 Jul 2006 17:28:30 -0700, "Today's Mulan"
<to*********@slidemail.comwrote:
I guess this is new, at least to people who don't know about this, like
me, please be prepared to give me a satifying answer,
so please tell me how the compiler "knows" variable "i" as in a
declaration of "int i" is of type "int"?

There is nothing magical about i. The compiler doesn't know anything
about i until you tell it. In the case you cite, the compiler
recognizes the keyword int and applies that meaning the object name
that follows. If you had written "double i;", i would be a double and
not an int.

What is your real question?

Are you trying to learn how to write a compiler?

Are you trying to understand how your compiler parses the code?
(If so, the answer is it depends on the compiler.)
Remove del for email
Decalring double and int is different to the original question's
meaning ?

Jul 17 '06 #4

"Today's Mulan" <to*********@slidemail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
I guess this is new, at least to people who don't know about this, like
me, please be prepared to give me a satifying answer,
so please tell me how the compiler "knows" variable "i" as in a
declaration of "int i" is of type "int"?
The compiler saves the variable name, i.e., identifier, and the variable
type, i.e., type-specifier, as two fields of a structure (which may have
more fields), usually in a binary tree (but, occasionally on stacks). The
information in the binary tree is what is left after the C code is lexed
(tokenized) and parsed (syntax checked). Since the information in the
binary tree _usually_ lacks lexical elements such as terminators,
punctuation, etc..., it is called an Abstract Syntax Tree (AST). If the
compiler implementors chose to retain the full lexical information of the C
code in the tree, it'd be called a Concrete Syntax Tree (CST). I guess if
you used stacks it'd be an "Abstract Syntax Stack"...
Rod Pemberton
Jul 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Tim Rentsch | last post by:
Here's another question related to 'volatile'. Consider the following: int x; void foo(){ int y; y = (volatile int) x;
81
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there...
50
by: Joseph Casey | last post by:
Greetings. I have read that the mistake of calling free(some_ptr) twice on malloc(some_data) can cause program malfunction. Why is this? With thanks. Joseph Casey.
2
by: Rajshekhar | last post by:
Hi all, Where can i get the complete details about the all types of errors and warnings that a C-compiler pops up..?? any pdfs or links or books to refer....! plz help me out.. Regards,...
15
by: Marc Thrun | last post by:
Hello, I've got a few questions: 1) Given the two structs struct A { int x; }; and
11
by: Sensei | last post by:
Hi again! I have still curiosity about the reason of some C constructs/keywords... The first is about static functions. What was the reason of restricting a function to be visible just in a...
7
by: Yuri_Юрий | last post by:
I'm confused about the VARIABLE LENGTH ARRAYS. {scanf("%d",&n);float a;} In which compiler can I use it? I tried VC++6.0 SP6,but it's reported error:CONSTANT EXPRESSION! Another question, What...
68
by: James Dow Allen | last post by:
The gcc compiler treats malloc() specially! I have no particular question, but it might be fun to hear from anyone who knows about gcc's special behavior. Some may find this post interesting;...
13
by: charpour | last post by:
Hello, in the program below: #include <stdio.h> int main(void) { int x = 1, y = 2, z; z = x+++y; return 0; }
10
by: JosephLee | last post by:
In Inside C++ object Model, Lippman said there are four cases in which compile will sythesize a default constructor to initialize the member variables if the constructor is absent: 1. there is a...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.