Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 21994

error: initializer element is not constant when initializing a structure by a function address

$
0
0

When I compile the the following code I get

error: initializer element is not constant

It does compile in Windows (MinGW) but not in Linux.

Structuremy_multiboot_header has to be initialized at compile time, not at load time.

#define LOAD_BASE 0x100000typedef struct{    int magic;    int flags;    int checksum;    int header_addr;    int load_addr;    int load_end_addr;    int bss_end_addr;    int entry_addr;    int mode_type;    int width;    int height;    int depth;} multiboot_header;int kernel_boot(void);const multiboot_header my_multiboot_header = {    0x1BADB002,    0x10003,    - (0x10003 + 0x1BADB002),    (int)&my_multiboot_header, // error: initializer element is not constant    LOAD_BASE,    0,    0,    (int)kernel_boot           // error: initializer element is not constant};int kernel_boot(){    while(1);    return 0xDEADC0de;}

Viewing all articles
Browse latest Browse all 21994

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>