Chinaunix首页 | 论坛 | 博客
  • 博客访问: 918303
  • 博文数量: 132
  • 博客积分: 9976
  • 博客等级: 中将
  • 技术积分: 1781
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-30 20:40
文章分类

全部博文(132)

文章存档

2013年(1)

2011年(1)

2010年(15)

2009年(77)

2008年(36)

2007年(2)

我的朋友

分类: C/C++

2009-02-20 13:31:58

my c test error log

=======================================================================
我的 c 代码:

#include
#include
#include

struct aa;

int
use_aa(int var)
{
  struct aa aatest;
  aatest.test_aa = var;
  strncpy(aatest.test_str, "struct aa test string", 80);
  printf(" test_aa = %d\n", aatest.test_aa);
  printf(" test_str = %s\n", aatest.test_str);
}

struct aa {
  int test_aa;
  char test_str[80];
};

void
main(void)
{
  use_aa(8);
  return 0;
}


以上代码编译时出错, 输出信息如下:
pre_struct_declare_2.c: In function ‘use_aa’:
pre_struct_declare_2.c:10: error: storage size of ‘aatest’ isn’t known
pre_struct_declare_2.c:20: confused by earlier errors, bailing out

解释:
----------------------------------------------------------------------------
from:

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



  #  
Old March 28th, 2007, 06:25 PM
Bo Persson
Guest
 
Posts: n/a
Default Re: compile error: storage size of 'var' isn't known

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



  #  
Old April 4th, 2007, 09:25 AM
=?Utf-8?B?R2Vvcmdl?=
Guest
 
Posts: n/a
Default Re: compile error: storage size of 'var' isn't known

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:
Quote:
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
>
>
>
>
  #  
Old April 4th, 2007, 04:55 PM
Bo Persson
Guest
 
Posts: n/a
Default Re: compile error: storage size of 'var' isn't known

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
----------------------------------------------------------------------------
from:

error: storage size of 'frm' isn't known


  • From:
  • Date: 11 Jul 2006 13:31:38 -0700

When I compile the code snipets below I'm producing the error: storage
size of 'frm' isn't known.

dll.h :
/*
* File: dll.cpp
* Defines the data link layer's interface.
*/

#ifndef __FRAME_
#define __FRAME_

typedef unsigned int frame_kind;
typedef unsigned int seq_nr;

struct {
frame_kind kind;
seq_nr seq;
seq_nr ack;
char data[100];
}; frame

#endif

dataLinkSend() :
void dataLinkSend(int sd, char* data, seq_nr last) {
struct frame frm;

frm.kind = data;
frm.seq = (last++)%3;
frm.ack = last;
frm.data = data;

if(send(sd, frm, sizeof(frm), 0) < 0) {
fprintf(stderr, "Couldn't send frm\n");
exit(1);
}
}

If you need the whole file that dataLinkSend() id in, let me know and I
can post it.

...................

Re: error: storage size of 'frm' isn't known


  • From: Michael Mair <>
  • Date: Tue, 11 Jul 2006 22:39:38 +0200

walsht@xxxxxxxxx schrieb:
When I compile the code snipets below I'm producing the error: storage
size of 'frm' isn't known.

Please provide a compiling minimal example inserted in your
message by copy and paste. Otherwise, important information
or the error itself may be missing or people may spot errors
that were not there in the original version.


typedef unsigned int frame_kind;
typedef unsigned int seq_nr;

struct {
frame_kind kind;
seq_nr seq;
seq_nr ack;
char data[100];
}; frame

This must not compile.

You mean:
struct frame {
....
};


dataLinkSend() :
void dataLinkSend(int sd, char* data, seq_nr last) {
struct frame frm;

As you did not really create the type "struct frame" above,
this type is not known, and so is its size...




Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
----------------------------------------------------------------------------
=======================================================================

阅读(902) | 评论(1) | 转发(0) |
0

上一篇:linux 加密文件

下一篇:网络相关论坛

给主人留下些什么吧!~~

chinaunix网友2010-02-06 13:38:43

您好! 请您看看这个页面的作用,我要怎样对待它 谢谢!