473,385 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Yacc/Bison: Trouble using struct in %union - "incomplete type" error

In my Yacc .y file I defined:

%union {
int value;
struct Symbol Sym;
}
The Symbol struct I defined in a header file I #included in the Prologue
section of the .y file as:

struct Symbol {
char *SymName; /* Name of symbol/token */
int SymType; /* Symbol type */
int SymValue;
};

However, on build I get:

bison -d prog.y
flex -t prog.l prog.lex.c
gcc -g -w -c prog.lex.c
In file included from prog.l:10:
prog.y:22: error: field `Sym' has incomplete type
make: *** [prog.lex.o] Error 1

If in the %union I make Sym a pointer to struct Symbol the build error
goes away. Can someone explain what is going wrong here and how I can
correct this to Sym is still just a struct?

--john
Jul 15 '06 #1
3 11717
On Sat, 15 Jul 2006 17:24:48 GMT, John Sasso <js******@nospam.com>
wrote in comp.lang.c:
In my Yacc .y file I defined:

%union {
int value;
struct Symbol Sym;
}
[snip]

This is not C, and not a C language issue, therefore off-topic in
comp.lang.c, followups set. I have no idea whether it is topical or
not in comp.os.linux.development.apps.

comp.lang.c removed from follow up.

--
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.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 15 '06 #2

"John Sasso" <js******@nospam.comwrote in message
news:Ax*******************@twister.nyroc.rr.com...
In my Yacc .y file I defined:

%union {
int value;
struct Symbol Sym;
}
The Symbol struct I defined in a header file I #included in the Prologue
section of the .y file as:

struct Symbol {
char *SymName; /* Name of symbol/token */
int SymType; /* Symbol type */
int SymValue;
};

However, on build I get:

bison -d prog.y
flex -t prog.l prog.lex.c
gcc -g -w -c prog.lex.c
In file included from prog.l:10:
prog.y:22: error: field `Sym' has incomplete type
make: *** [prog.lex.o] Error 1

If in the %union I make Sym a pointer to struct Symbol the build error
goes away. Can someone explain what is going wrong here and how I can
correct this to Sym is still just a struct?
I can't help very much from what you posted. All I can do is review how you
should include the file.

Let's say your struct:

struct Symbol {
char *SymName; /* Name of symbol/token */
int SymType; /* Symbol type */
int SymValue;
};

is in "symbol.h".

Then, the .y Bison grammar file, should have this:

%{
#include "symbol.h"
%}
%union {
int value;
struct Symbol Sym;
}

And, the .l Flex grammar file, should have this:

%{
#include "symbol.h"
#include "y.tab.h"
%}
Notice that "y.tab.h" is included in the .l Flex grammar and it comes after
"symbol.h". That's about all I can help you with.
Rod Pemberton
Jul 16 '06 #3
John Sasso <js******@nospam.comwrote:
# In my Yacc .y file I defined:
#
# %union {
# int value;
# struct Symbol Sym;
# }
#
#
# The Symbol struct I defined in a header file I #included in the Prologue
# section of the .y file as:
#
# struct Symbol {
# char *SymName; /* Name of symbol/token */
# int SymType; /* Symbol type */
# int SymValue;
# };
#
# However, on build I get:
#
# bison -d prog.y
# flex -t prog.l prog.lex.c
# gcc -g -w -c prog.lex.c
# In file included from prog.l:10:
# prog.y:22: error: field `Sym' has incomplete type
# make: *** [prog.lex.o] Error 1

Are you also #including the header file in prog.l? The C files generated
by bison and lex are separate and should not be expected to known about
the other's includes. While bison might write out an interface file with
its unions and symbol definitions, you should only expect that to have
the declarations bison creates and not transitively declarations from
other include files.

# If in the %union I make Sym a pointer to struct Symbol the build error
# goes away. Can someone explain what is going wrong here and how I can
# correct this to Sym is still just a struct?

All struct pointers look the same; the compile can allocate the union
because it will know the size of the struct pointer even if it doesn't
know the size of the struct.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
You hate people.
But I love gatherings. Isn't it ironic.
Jul 16 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Lou Pecora | last post by:
g++ compiler error question. I have a container C whose constructor takes a class B that is inherited from an abstract class A. So I have the line of code: B binstance; C ...
0
by: hamstak | last post by:
While attempting to perform a build on an .aspx page from within VS 2005 I receive the "Could not load type" error pertaining to the class representing the page. The class is derived from a custom...
3
by: Alden Pierre | last post by:
Hello, I'm having a hard time trying to figure why my code will not compile. When I try to compile the code, I get the non-aggregate type error. Any ideas on what I'm doing wrong? ...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
13
by: imutate | last post by:
Hi, I am migrating some std::vectors to use a template instead, but I get an incomplete type error in a struct declaration. #include <vector> template < typename T > class Vec : public...
2
by: cr55 | last post by:
I was wondering if anyone can help me with this programming code as i keep getting errors and am not sure how to fix them. The error code displayed now is error: C2228: left of '.rent' must have...
3
by: eros | last post by:
ALTER TABLE public.postcodes ALTER COLUMN machi TYPE varchar(100); Error: ERROR: syntax error at or near "TYPE"; Error while executing the query (State:42601, Native Code: 7) I am using...
2
by: unclefester | last post by:
I have two classes: Test1 and Test2. Test1 has a field of data type Test2, & vice versa. I need some help in avoiding the incomplete type error ("Error: field has incomplete type"). Test1.h ...
5
by: tejesh | last post by:
I am trying to compile the following code int backend_sm_run(struct interface_data *ctx) { xsup_assert((ctx != NULL), "ctx != NULL", TRUE); xsup_assert((ctx->statemachine != NULL),...
5
by: Anuz | last post by:
Hi all, While compiling a driver, I am getting this error: error: dereferencing pointer to incomplete type int __kc_adapter_clean(struct net_device *netdev, int *budget) { /*some...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.