This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: bool and gcc

On Monday, August 10, 1998 10:37 AM, Inquisitor Nikodemus wrote:

> Does gcc (egcs exactly) support boolean (bool) type?


> What does the following mean ?
> .cc:120: warning: name lookup of `index' changed for new ANSI `for'
> .cc:119: warning:   using obsolete binding at `index'
> What's that "new ANSI 'for' scoping" ?

Old (pre final ANSI standard) 'for' scoping made the following snippet

	for (int i = 0; i < N; i++) {
		// Use i inside the 'for' block
	// Use i outside the 'for' block

I.e., it meant that a variable introduced and declared in the initialization
part of the 'for' statement would be valid after the 'for' (until the end of
the block enclosing the 'for' statement).  The new ANSI scoping rules
make 'i' unavailable outside of the 'for' statement body.

To accomodate the large amount of code that relies on the old scoping,
the compiler takes extra pains to detect and allow this usage (with
warnings to induce the code writer to change it).

A standards-compliant workaround would be:

		int i;
		for (i = 0; i < N; i++) {
			// Use 'i' inside the 'for' block
		// Use 'i' outside the 'for' block
	// 'i' is no longer available here

where the outer braces limit the variable scope (a good idea).
Or just drop the outer braces to get the pre-standard scope.

> And the next one :
> request for member `figure' in `nodebufstat', which is of
> non-aggregate type `node *'
> Line 122 is :  *(nodebufstat).figure=-1 ;

Your line, fully parenthesized to take into account operator precedence
would look:

	(*((nodebufstat).figure)) = -1;

In other words, '.' is more binding than '*'.  Therefore, in your code, '.'
is trying to find the 'figure' member in 'nodebufstat', and then tries
to apply the '*' indirection to the member's value.  First of all,
'nodebufstat' is not an aggregate (structure, union or class) but
a pointer to such.  And second, the 'figure' member is not a pointer.
The compiler is, thankfully, stopping at the first error instead of
producing a cascade.

A corrected line would be

	(*nodebufstat).figure = -1;

or, as is the customary way:

	nodebufstat->figure = -1;

remembering that


is always equivalent to


where 'a' must be an expression that evaluates to a pointer to an
aggregate that has 'b' as a member.  Bot '.' and '->' have the same
precendence and bind left to right.

Leo Mauro
Principal Scientist
TeleSys Technologies, Inc.

For help on using this list (especially unsubscribing), send a message to
"" with one line of text: "help".

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]