struct definition in header file: type defaults to 'int'

RatDon

I've a structure declaration and definition in header file header.h as:

#include <linux/slab.h>

struct hello{
    int a;
    char b;
};

extern struct hello *hello;

In file1.c I've:

#include<header.h>

struct hello *hello;
hello=kmalloc(sizeof(struct hello), __GFP_REPEAT);
kfree(hello);    //just to check later if 'hello' -
hello=NULL;      //-is initialized or not.

In file2.c I've:

#include<header.h>

The struct variable hello is used in file1.c and file2.c.

But while compiling I get an error:

file1.c:3:1 error: type defaults to 'int' in declaration of 'hello' [-Werror=implicit-int]
file1.c:4:1 error: conflicting types for 'hello'
file1.c:3:16 note: previous declaration of 'hello' was here 
 extern struct hello *hello;

I've never used variable definition in header file. Searched online and got this from few sources. Unable to find what is wrong. A lot of other errors are there after this which originates due to the mentioned error.

Edited to include the proper codes.

unwind

Is this:

hello=kmalloc(sizeof(struct hello), __GFP_REPEAT);

really at file-level scope like that? You can't have code like that outside a function in C, but I would expect a different error message.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

我在哪里可以得到`struct file * file_open(const char * path,int flags,int rights)的手册页?

来自分类Dev

Spark IllegalArgumentException:列要素的类型必须为struct <type:tinyint,size:int,indices:array <int>,values:array <double >>

来自分类Dev

键入punning:int []和struct {int…}

来自分类Dev

从int到struct的麻烦转换

来自分类Dev

int *从struct *指向的递增值

来自分类Dev

删除地图<int,list<struct*>>

来自分类Dev

declare Struct in Header and use in multiple Sources

来自分类Dev

IllegalArgumentException:列必须为struct <type:tinyint,size:int,indices:array <int>,values:array <double >>类型,但实际上是double类型。

来自分类Dev

struct file_operations与struct vnodeops

来自分类Dev

struct {a int; b int}和struct {b int; a int}有什么区别?

来自分类Dev

what is the correct way to add type definition for this module

来自分类Dev

int double struct和Enum ValueType

来自分类Dev

struct.pack()失败,且int> 127

来自分类Dev

关于使用int类型的struct hack

来自分类Dev

C scanf int转换为struct

来自分类Dev

Int在struct中不起作用

来自分类Dev

更改链表中的struct中的int值

来自分类Dev

map [int] interface {}与map [int] struct {}的内存分配

来自分类Dev

将 [Int:String] 字典存储到 user.defaults 因 SIGABRT 错误而崩溃

来自分类Dev

Unknown type name with typedef struct in C

来自分类Dev

header(“ Content-type:application / json”);`的用法

来自分类Dev

使用--defaults-file选项安装MySql服务不会安装服务

来自分类Dev

将Type Int转换为Type Byte

来自分类Dev

C将struct dirent *转换为FILE *

来自分类Dev

function foo that has the type ’a * ’a -> int

来自分类Dev

头文件中的struct定义:类型默认为'int'

来自分类Dev

将python转换为java:struct.pack('h',int)

来自分类Dev

在C中的struct中初始化int数组

来自分类Dev

Python 3 Struct解压缩int和bytearray

Related 相关文章

  1. 1

    我在哪里可以得到`struct file * file_open(const char * path,int flags,int rights)的手册页?

  2. 2

    Spark IllegalArgumentException:列要素的类型必须为struct <type:tinyint,size:int,indices:array <int>,values:array <double >>

  3. 3

    键入punning:int []和struct {int…}

  4. 4

    从int到struct的麻烦转换

  5. 5

    int *从struct *指向的递增值

  6. 6

    删除地图<int,list<struct*>>

  7. 7

    declare Struct in Header and use in multiple Sources

  8. 8

    IllegalArgumentException:列必须为struct <type:tinyint,size:int,indices:array <int>,values:array <double >>类型,但实际上是double类型。

  9. 9

    struct file_operations与struct vnodeops

  10. 10

    struct {a int; b int}和struct {b int; a int}有什么区别?

  11. 11

    what is the correct way to add type definition for this module

  12. 12

    int double struct和Enum ValueType

  13. 13

    struct.pack()失败,且int> 127

  14. 14

    关于使用int类型的struct hack

  15. 15

    C scanf int转换为struct

  16. 16

    Int在struct中不起作用

  17. 17

    更改链表中的struct中的int值

  18. 18

    map [int] interface {}与map [int] struct {}的内存分配

  19. 19

    将 [Int:String] 字典存储到 user.defaults 因 SIGABRT 错误而崩溃

  20. 20

    Unknown type name with typedef struct in C

  21. 21

    header(“ Content-type:application / json”);`的用法

  22. 22

    使用--defaults-file选项安装MySql服务不会安装服务

  23. 23

    将Type Int转换为Type Byte

  24. 24

    C将struct dirent *转换为FILE *

  25. 25

    function foo that has the type ’a * ’a -> int

  26. 26

    头文件中的struct定义:类型默认为'int'

  27. 27

    将python转换为java:struct.pack('h',int)

  28. 28

    在C中的struct中初始化int数组

  29. 29

    Python 3 Struct解压缩int和bytearray

热门标签

归档