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 -
#include "goo.h"
-
-
int main (int argc, char** argv)
-
{
-
t_st var;
-
var.member = 100;
-
return 0;
-
}
-
goo.c -
struct st {
-
-
int member;
-
-
};
-
-
goo.h
thanks in advance,
George 3 11903
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
::
:: -
:: #include "goo.h"
-
::
-
:: int main (int argc, char** argv)
-
:: {
-
:: t_st var;
-
:: var.member = 100;
-
:: return 0;
-
:: }
-
::
::
:: goo.c
::
:: -
:: struct st {
-
::
-
:: int member;
-
::
-
:: };
-
::
-
::
::
:: goo.h
::
:: -
:: typedef struct st t_st;
-
::
::
::
:: thanks in advance,
:: George
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
::
:: -
:: #include "goo.h"
-
::
-
:: int main (int argc, char** argv)
-
:: {
-
:: t_st var;
-
:: var.member = 100;
-
:: return 0;
-
:: }
-
::
::
:: goo.c
::
:: -
:: struct st {
-
::
-
:: int member;
-
::
-
:: };
-
::
-
::
::
:: goo.h
::
:: -
:: typedef struct st t_st;
-
::
::
::
:: thanks in advance,
:: George
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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=' in '*this =
CTest::operator+(CTest&)((+t2))'
test2.cpp:49: error: candidates are: CTest CTest::operator=(CTest&)
make: *** Error 1
|
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 absolute address of alpha to
access to it. What confuses me is that when the variable is dynamically
allocated, how does the compiler implement it? We...
|
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 rightType;
|
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 machine.
When I try to compile PostgreSQL 7.2.4 or 7.4.1 then I get
|gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations...
|
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
structures are read only)
Ideally one should be able to put the redundant
information there automatically so no mistakes are possible, but in a...
| |
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
|
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 since longs are not the same size
on win64 and linux x64) I would like to do a check at compile time to make
sure things are correct. This will ease...
|
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 message is:
E:\software\development\boost_1_35_0\boost_1_35_0>bjam --
toolset=msvc-7.1 --variant=release --threading=multi --link=shared --
|
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 --
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |