Re: mutually referential (Pg 140 K&R2)
- From: Lawrence Kirby <lknews@xxxxxxxxxxxxxxx>
- Date: Mon, 25 Apr 2005 17:38:29 +0100
On Fri, 22 Apr 2005 22:36:14 -0700, Barry Schwarz wrote:
> On 22 Apr 2005 21:13:49 -0700, "G Patel" <gaya.patel@xxxxxxxxx> wrote:
....
>>I ran the following test program through my C compiler to see if it
>>would compile:
>>
>>#include <stdlib.h>
You don't need <stdlib.h> for this code but you do need to #include
<stdio.h> since the code uses printf().
>>struct t
>>{
>> struct s *p; /* type 'struct s' is not visible here */
>>};
>>
>>struct s
>>{
>> struct t *q;
>>};
>>
>>int main()
>>{
>> printf("Hello world\n");
>> return 0;
>>}
>>
>>
>>It compiled and ran without any noticeable problems. I expected it to
>>complain about the line I've commented above.
>>
>>How is this valid when the type 'struct s' is not in scope when *p is
>>declared as a member of the type struct t?
>>
>>If this is 'valid' please tell me why scopes don't apply here. If this
>>is 'not valid' please tell me how I can declare mutually referential
>>struct types.
>>
>
> The fact that you compiler does not generate a diagnostic has no
> bearing on whether the code is valid or not. The opposite is also
> true. The compiler is allowed to generate a diagnostic even if the
> code is perfectly valid.
>
> Maybe you should raise the warning level on your compiler.
>
> Maybe your compiler is defective in this area.
If we add #include <stdio.h> the code is perfectly valid. I don't see any
defect in the area under discussion.
Lawrence
.
- References:
- mutually referential (Pg 140 K&R2)
- From: G Patel
- Re: mutually referential (Pg 140 K&R2)
- From: Barry Schwarz
- mutually referential (Pg 140 K&R2)
- Prev by Date: Re: How to remove and substitute characters within a string
- Next by Date: Re: How is strlen implemented?
- Previous by thread: Re: mutually referential (Pg 140 K&R2)
- Next by thread: Re: mutually referential (Pg 140 K&R2)
- Index(es):
Relevant Pages
|