473,403 Members | 2,222 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,403 software developers and data experts.

K&R2 variable definition

Hello everybody,
I cannot find where in the K&R2 it is stated that variables must be
defined at the beginning
of a block and not within other lines.
In Section 1.2 I read:
In C, all variables must be declared before they are used, usually at
the beginning of the
function before any executable statements.
USUALLY does not mean ABSOLUTELY, correct?
I know that in C99 it is possible, but I'm interested in C89.
Can anyone tell me something about?
Thank you!
Claus

Oct 26 '06 #1
5 1447
On 26 Oct 2006 06:42:38 -0700, "Clausfor" <cl******@gmail.comwrote:
>Hello everybody,
I cannot find where in the K&R2 it is stated that variables must be
defined at the beginning
of a block and not within other lines.
In Section 1.2 I read:
In C, all variables must be declared before they are used, usually at
the beginning of the
function before any executable statements.
USUALLY does not mean ABSOLUTELY, correct?
I know that in C99 it is possible, but I'm interested in C89.
Can anyone tell me something about?
Thank you!
Claus
Take a look at page 25:

"A funtion definition has this form:

return-type function-name (parameter declarations, if any)
{
declarations
statements
}
"

That's it, and it's clear

Zara
Oct 26 '06 #2
In article <11**********************@m73g2000cwd.googlegroups .com>,
Clausfor <cl******@gmail.comwrote:
In C, all variables must be declared before they are used, usually at
the beginning of the
function before any executable statements.
USUALLY does not mean ABSOLUTELY, correct?
You can declare variable in inner blocks:

int foo(void)
{
int a;
...
{
int b;
...
}
}

-- Richard
Oct 26 '06 #3
Yes... clear... thank you!
Claus

Oct 26 '06 #4
Clausfor wrote:
Hello everybody,
I cannot find where in the K&R2 it is stated that variables must be
defined at the beginning
of a block and not within other lines.
Try the grammar.

(Can't cite page & name, as my copy of K&R2 is at home.)

--
Chris "back home once again ...." Dollin
"Reaching out for mirrors hidden in the web." - Renaissance, /Running Hard/

Oct 26 '06 #5
Clausfor said:
Hello everybody,
I cannot find where in the K&R2 it is stated that variables must be
defined at the beginning
of a block and not within other lines.
You're looking for an explicit prohibition, but you won't find one. What you
have instead is absence of permission. See page 236, grammar for
compound-statement, which shows that declarations *may* occur at the
beginning of a compound statement. Now look for other places in the grammar
where declarations *may* occur, and look at... well, at what isn't there.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Oct 26 '06 #6

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

Similar topics

16
by: TTroy | last post by:
I FOUND MAJOR ERRORS in K&R2 (making it almost useless for the herein mentioned topics). K&R2 Section 5.9 Pointers vs. Multidimension Arrays starts of like this... "Newcomers to C are...
14
by: G Patel | last post by:
Pg. 140 of K&R2 shows an example of mutually referential structure declarations... struct t { struct s *p; }; struct s {
4
by: arnuld | last post by:
as i said, i have restarted the book because i overlooked some material. i want to have some comments/views on this solution. it runs fine, BTW. ------------------ PROGRAMME -------------- /*...
16
by: arnuld | last post by:
i have created solution which compiles and runs without any error/ warning but it does not work. i am not able to understand why. i thought it is good to post my code here for correction before...
4
by: arnuld | last post by:
any suggestions for improvement: -------------- PROGRAMME ------------- /* K&R2: section 1.5.3 exercise 1-10 STATEMENT: write a programme to copy its input to output, replacing each TAB by...
12
by: arnuld | last post by:
i was able to create a solution for a Horizontal-Histogram. i was completely unable to understand this Vertical-Histogram phenomenon. even though i have looked at the solution at this page: ...
16
by: arnuld | last post by:
i am not able to make it work. it compiles without any error but does not work: what i WANTED: 1.) 1st we will take the input in to an array. (calling "getline" in "main") 2.) we will print...
88
by: santosh | last post by:
Hello all, In K&R2 one exercise asks the reader to compute and print the limits for the basic integer types. This is trivial for unsigned types. But is it possible for signed types without...
15
by: arnuld | last post by:
STATEMENT: Write the function strindex(s, t), which returns the position of the rightmost occurence of t in s, or -1 if there is none. PURPOSE: this program prints the index of the rightmost...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.