f



Error E2140 deque.c 293: Declaration is not allowed here

typedef struct {
    short   dataType;
    YYSTYPE  datum;
} SyntaxNode;

struct deque_node {
    SyntaxNode key;
    struct deque_node * prev;
    struct deque_node * next;
};

SyntaxNode deque_begin(void) {
    deque_p = deque_head;
    SyntaxNode t;
    if (NULL != deque_p) {
        t=deque_p->key;
    }
    return t;
}

SyntaxNode deque_end(void) {
    deque_p = deque_tail;
    SyntaxNode t;
    if (deque_p != NULL) {
        t=deque_p->key;
    }
    return t;
}

Error E2140 deque.c 293: Declaration is not allowed here in function
deque_begin

Error E2140 deque.c 302: Declaration is not allowed here in function
deque_end

errors occur wherever this line is found:
    SyntaxNode t;

it is typedef struct.  doesn't complain about the struct with the key
for some reason.
I am using Borland C++ 5.5 free edition.
0
jmichae3
10/23/2008 2:39:26 AM
comp.os.programmer.win32 14523 articles. 0 followers. Post Follow

5 Replies
411 Views

Similar Articles

[PageSpeed] 37

On Oct 22, 7:39=A0pm, jmich...@yahoo.com wrote:
> typedef struct {
> =A0 =A0 short =A0 dataType;
> =A0 =A0 YYSTYPE =A0datum;
>
> } SyntaxNode;

I should mention that YYSTYPE is a union.
typedef union YYSTYPE {
    int ival;
    short sval;
    short bval;
    double dval;
    char * strval;
    long lval;
} YYSTYPE;
0
jmichae3
10/23/2008 4:33:13 AM
jmichae3@yahoo.com wrote:
> On Oct 22, 7:39 pm, jmich...@yahoo.com wrote:
>> typedef struct {
>>     short   dataType;
>>     YYSTYPE  datum;
>>
>> } SyntaxNode;
> 
> I should mention that YYSTYPE is a union.
> typedef union YYSTYPE {
>     int ival;
>     short sval;
>     short bval;
>     double dval;
>     char * strval;
>     long lval;
> } YYSTYPE;

Seems more a C question than one for comp.os.ms-windows.programmer.win32 
(although you got the 'programmer' part).

Move those 'SyntaxNode t' lines one line up -- before the first code. 
Although C++ (and Borland's is an excellent version!) should not have a 
problem with this, in any case, you rule this one out.

Why do you use 'YYSTYPE' twice in the union declaration? Could that 
cause the actual error?

[Jw]
0
Jongware
10/23/2008 10:29:53 AM
On Wed, 22 Oct 2008 19:39:26 -0700 (PDT), jmichae3@yahoo.com wrote in
comp.os.ms-windows.programmer.win32:

> typedef struct {
>     short   dataType;
>     YYSTYPE  datum;
> } SyntaxNode;
> 
> struct deque_node {
>     SyntaxNode key;
>     struct deque_node * prev;
>     struct deque_node * next;
> };
> 
> SyntaxNode deque_begin(void) {
>     deque_p = deque_head;

What is deque_p, you haven't shown us a declaration or definition?

>     SyntaxNode t;
>     if (NULL != deque_p) {
>         t=deque_p->key;
>     }
>     return t;
> }
> 
> SyntaxNode deque_end(void) {
>     deque_p = deque_tail;
>     SyntaxNode t;
>     if (deque_p != NULL) {
>         t=deque_p->key;
>     }
>     return t;
> }
> 
> Error E2140 deque.c 293: Declaration is not allowed here in function
> deque_begin
> 
> Error E2140 deque.c 302: Declaration is not allowed here in function
> deque_end
> 
> errors occur wherever this line is found:
>     SyntaxNode t;
> 
> it is typedef struct.  doesn't complain about the struct with the key
> for some reason.
> I am using Borland C++ 5.5 free edition.

I am going to assume that deque_p is a pointer object defined at file
scope.  In that case, the statement:

   deque_p = /* whatever */

....is an executable statement.

The fact that the error messages you quoted list the file name as
"deque.c" tells me the rest.

In versions of C before the 1999 standard, all declarations inside a
block must come before any executable statements.  And Borland 5.5
most certainly does not conform to the 1999 C standard.

So, as Jongware said, move the defining declaration of 't' before the
assignment statement to deque_p.

-- 
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
0
Jack
10/24/2008 1:39:50 AM
<jmichae3@yahoo.com> wrote in message 
news:de138108-287d-450e-8725-373d2ca9e130@i20g2000prf.googlegroups.com...
> typedef struct {
>    short   dataType;
>    YYSTYPE  datum;
> } SyntaxNode;
>
> struct deque_node {
>    SyntaxNode key;
>    struct deque_node * prev;
>    struct deque_node * next;
> };
>
> SyntaxNode deque_begin(void) {
>    deque_p = deque_head;

What is deque_p? Where is it declared?  Is it a global variable? If not, the 
compiler has no idea what type it is at this point.

>    SyntaxNode t;
>    if (NULL != deque_p) {
>        t=deque_p->key;
>    }
>    return t;
> }
>
> SyntaxNode deque_end(void) {
>    deque_p = deque_tail;

Same here, what is deque_p?

>    SyntaxNode t;
>    if (deque_p != NULL) {
>        t=deque_p->key;
>    }
>    return t;
> }
>
> Error E2140 deque.c 293: Declaration is not allowed here in function
> deque_begin
>
> Error E2140 deque.c 302: Declaration is not allowed here in function
> deque_end
>
> errors occur wherever this line is found:
>    SyntaxNode t;

Many times the point of error emission is not at the error itself. If the 
line of emission is OK, then start looking back from that point.  See my 
comments on the preceding lines.
>
> it is typedef struct.  doesn't complain about the struct with the key
> for some reason.
> I am using Borland C++ 5.5 free edition. 


0
David
10/24/2008 5:06:06 PM
<jmichae3@yahoo.com> wrote in message 
news:9df39e30-48ad-45c8-b70a-3928ecd55a14@g17g2000prg.googlegroups.com...
On Oct 22, 7:39 pm, jmich...@yahoo.com wrote:
> typedef struct {
> short dataType;
> YYSTYPE datum;
>
> } SyntaxNode;

In addition to what others have said (we need all declarations provided), I 
will contribute a style response in case you are just starting out. Do not 
put the opening brace at the end of a line - it is hard to read and hard to 
match braces when you have a lot of code. Remember whitespace is free so use 
it !!!!

eg:

typedef struct
{
    short             dataType;
    YYSTYPE   datum;

} SyntaxNode;


Now you can see the matching pairs of braces easily. This is obviously a 
simple case but image nested for/if/while loops - that is when you get a 
real benefit doing code walkthroughs as everything is much more obvious.

Leslie.


0
Leslie
10/26/2008 1:28:58 AM
Reply: