Google Groups unterstützt keine neuen Usenet-Beiträge oder ‑Abos mehr. Bisherige Inhalte sind weiterhin sichtbar.

Reference to Array bug

15 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Lindsay F. Marshall

ungelesen,
26.03.1990, 06:06:3926.03.90
an
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

ungelesen,
04.04.1990, 17:04:4604.04.90
an
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

ungelesen,
04.04.1990, 23:48:2204.04.90
an
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 neue Nachrichten