Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reference to Array bug

15 views
Skip to first unread message

Lindsay F. Marshall

unread,
Mar 26, 1990, 6:06:39 AM3/26/90
to
This code (which passes CC) :-

void example()
{
char x[80];
char (&refx)[] = x;

}

causes the following error messages

t.C: In function void example ():
t.C:4: `refx' undeclared (first use this function)
t.C:4: (Each undeclared identifier is reported only once
t.C:4: for each function it appears in.)
t.C:4: parse error before `]'

The whole area of references to arrays seems to have problems.

Lindsay
--
MAIL : Lindsay....@newcastle.ac.uk (UUCP: s/\(.*\)/...!ukc!\1/)
POST : Computing Laboratory, The University, Newcastle upon Tyne, UK NE1 7RU
VOICE: +44-91-222-8267 FAX: +44-91-222-8232

102SMI

unread,
Apr 4, 1990, 5:04:46 PM4/4/90
to
In article <1990Mar26.1...@newcastle.ac.uk> Lindsay....@newcastle.ac.uk (Lindsay F. Marshall) writes:
>This code (which passes CC) :-
>
>void example()
>{
> char x[80];
> char (&refx)[] = x;
>
>}

I came across this with function pointers. It seems as if g++ gets confused
when it sees the `(' after `char'.

Fix: put the keyword `auto' in front. eg, `auto char (&refx)[] = x;'

It worked for the function pointer problem and compiled (have tested
execution) for your example.

This only seems to be a problem with local variables. I've used
function pointers successfully as class members without `auto'.
-Daniel
Daniel Pezely <pez...@udel.edu> (NSFnet) 728 Bent Ln, Newark, DE 19711 | Skate
Comp Sci Lab, Smith Hall, U of Delaware, Newark, DE 19716; 302/451-6339 | ICE

Ronald Guilmette

unread,
Apr 4, 1990, 11:48:22 PM4/4/90
to
In article <15...@nigel.udel.EDU> pez...@ee.udel.edu (Daniel Pezely) writes:
>In article <1990Mar26.1...@newcastle.ac.uk> Lindsay....@newcastle.ac.uk (Lindsay F. Marshall) writes:
>>This code (which passes CC) :-
>>
>>void example()
>>{
>> char x[80];
>> char (&refx)[] = x;
>>
>>}
>
>I came across this with function pointers. It seems as if g++ gets confused
>when it sees the `(' after `char'.
>
>Fix: put the keyword `auto' in front. eg, `auto char (&refx)[] = x;'
>
>It worked for the function pointer problem and compiled (have tested
>execution) for your example.
>
>This only seems to be a problem with local variables. I've used
>function pointers successfully as class members without `auto'.

The syntax supported by cfront for declaring pointers to functions or
pointers to arrays (or references to functions or references to arrays)
does not work in g++ in two contexts, i.e. local declarations, and
declarations of formal parameters.

In these cases, you must use a typedef or add the word 'auto'.

If you are dealing with formal parameters, you had better use a typedef
if you want your code to be portable to cfront.


// Ron Guilmette (r...@ics.uci.edu)
// C++ Entomologist
// Motto: If it sticks, force it. If it breaks, it needed replacing anyway.

0 new messages