473,322 Members | 1,778 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,322 software developers and data experts.

compile error: storage size of 'var' isn't known

Hello everyone,
I get a strange compile error when compile such simple program. Any ideas?

foo.c: In function `main':
foo.c:5: error: storage size of 'var' isn't known

foo.c

Expand|Select|Wrap|Line Numbers
  1. #include "goo.h"
  2.  
  3. int main (int argc, char** argv)
  4. {
  5. t_st var;
  6. var.member = 100;
  7. return 0;
  8. }
  9.  
goo.c

Expand|Select|Wrap|Line Numbers
  1. struct st {
  2.  
  3. int member;
  4.  
  5. };
  6.  
  7.  
goo.h

Expand|Select|Wrap|Line Numbers
  1. typedef struct st t_st;
  2.  

thanks in advance,
George
Mar 28 '07 #1
3 11889
George wrote:
:: Hello everyone,
::
::
:: I get a strange compile error when compile such simple program. Any
:: ideas?
::
:: foo.c: In function `main':
:: foo.c:5: error: storage size of 'var' isn't known

The compiler can figure out that 'var' is of type 't_st', which is another
name for a struct named 'st'. However, it cannot see what 'st' is, as it is
hidden in another translation unit.

You can have a pointer to st without knowing exactly what it is, but you
cannot have a variable of type st without seeing the full definition.
Bo Persson

::
:: foo.c
::
::
Expand|Select|Wrap|Line Numbers
  1. :: #include "goo.h"
  2. ::
  3. :: int main (int argc, char** argv)
  4. :: {
  5. ::    t_st var;
  6. ::    var.member = 100;
  7. ::    return 0;
  8. :: }
  9. :: 
::
:: goo.c
::
::
Expand|Select|Wrap|Line Numbers
  1. :: struct st {
  2. ::
  3. :: int member;
  4. ::
  5. :: };
  6. ::
  7. :: 
::
:: goo.h
::
::
Expand|Select|Wrap|Line Numbers
  1. :: typedef struct st t_st;
  2. :: 
::
::
:: thanks in advance,
:: George

Mar 28 '07 #2
Thanks Bo Persson!
I want to confirm that, if I define a struct in .c file, I can only use the
struct in the same .c file, and have no walk-around to utilize the struct in
other .c file.

If I want to use the struct in multiple .c files, I have to define it in .h
file?
regards,
George

"Bo Persson" wrote:
George wrote:
:: Hello everyone,
::
::
:: I get a strange compile error when compile such simple program. Any
:: ideas?
::
:: foo.c: In function `main':
:: foo.c:5: error: storage size of 'var' isn't known

The compiler can figure out that 'var' is of type 't_st', which is another
name for a struct named 'st'. However, it cannot see what 'st' is, as it is
hidden in another translation unit.

You can have a pointer to st without knowing exactly what it is, but you
cannot have a variable of type st without seeing the full definition.
Bo Persson

::
:: foo.c
::
::
Expand|Select|Wrap|Line Numbers
  1. :: #include "goo.h"
  2. ::
  3. :: int main (int argc, char** argv)
  4. :: {
  5. ::    t_st var;
  6. ::    var.member = 100;
  7. ::    return 0;
  8. :: }
  9. :: 
::
:: goo.c
::
::
Expand|Select|Wrap|Line Numbers
  1. :: struct st {
  2. ::
  3. :: int member;
  4. ::
  5. :: };
  6. ::
  7. :: 
::
:: goo.h
::
::
Expand|Select|Wrap|Line Numbers
  1. :: typedef struct st t_st;
  2. :: 
::
::
:: thanks in advance,
:: George

Apr 4 '07 #3
George wrote:
:: Thanks Bo Persson!
::
::
:: I want to confirm that, if I define a struct in .c file, I can only
:: use the struct in the same .c file, and have no walk-around to
:: utilize the struct in other .c file.

The "work-around" is to define the struct identically in both .c files. That
in effect simulates what happens when you include a .h file in both .c
files.

Not recommended! :-)

::
:: If I want to use the struct in multiple .c files, I have to define
:: it in .h file?

This is the reason for having .h files in the first place. It lets you share
declarations between several implementation files.
Bo Persson
Apr 4 '07 #4

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

Similar topics

5
by: xuatla | last post by:
Hi, I encountered the following compile error of c++ and hope to get your help. test2.cpp: In member function `CTest CTest::operator+=(CTest&)': test2.cpp:79: error: no match for 'operator='...
17
by: newbiecpp | last post by:
I have hard time to understand run-time environment. Let assume that I have a program that has a simple variable alpha. When this variable is statically allocated, the compiler can use the...
5
by: Carmine Cairo | last post by:
Hi, I'm working on a project and today I've note a little problem during the compile fase. Here a little piece of code: // 1st version welldone = 0; size = p->getSize(); backbone = new...
2
by: Holger Marzen | last post by:
Hi all, I want to upgrade Postgres 7.1.3 on an old Debian Slink machine (with glibc 2.0.7 and Kernel 2.2.17). That machine runs fine and I can not simply upgrade the OS because it's a busy 24/7...
10
by: Bart Goeman | last post by:
Hi, I have a question about how to put redundant information in data structures, initialized at compile time. This is often necessary for performance reasons and can't be done at run time (data...
1
by: Madhusuthanan Seetharam | last post by:
Hi all, I'm a newbie to C. What does the error message "storage size of 'xxxxx' isn't known mean? TIA, - Madhu
4
by: John Smith | last post by:
Hi I'm porting some C++ code to new platforms and have some 1-byte aligned structures which need a specific size. Since datatypes can vary on different platforms (which I found out the hard way...
2
by: BruceWho | last post by:
I downloaded boost1.35.0 and built it with following command: bjam --toolset=msvc-7.1 --variant=release --threading=multi -- link=shared --with-system stage and it failed to compile, error...
27
by: CodeMonk3y | last post by:
gotta question on sizeof keyword does the sizeof keyword calcuates the size at compile time or run time ?? -- Posted on news://freenews.netfront.net - Complaints to news@netfront.net --
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.