Yet another kernel problem YaKP (global variables)

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
guest

Yet another kernel problem YaKP (global variables)

Post by guest »

Ok now I've a problem with global variables, if declare a variable global the value of it is zero!:

Code: Select all

unsigned int n = 15;

int main()
{
  if(n == 0)
    putstr("n == 0");      // this is out
  else
    putstr("n == !0");
}
local variables work:

Code: Select all

int main()
{
  unsigned int n = 15;

  if(n == 0)
    putstr("n == 0");
  else
    putstr("n == !0");  // this is out
}
Therx

Re:Yet another kernel problem YaKP (global variables)

Post by Therx »

Are you loading your DATA section correctly? Or have you written over it by mistake in the program somewhere?
guest

Re:Yet another kernel problem YaKP (global variables)

Post by guest »

do you mean in my linker script??

here is it:

/* Link.ld */
OUTPUT_FORMAT("binary")
ENTRY(start)
SECTIONS
{
.text 0x100000 :
{
code = .; _code = .; __code = .;
*(.text)
. = ALIGN(4096);
}

.data :
{
__CTOR_LIST__ = .; LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2) *(.ctors) LONG(0) __CTOR_END__ = .;
__DTOR_LIST__ = .; LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2) *(.dtors) LONG(0) __DTOR_END__ = .;

data = .; _data = .; __data = .;
*(.data)
. = ALIGN(4096);
}

.bss :
{
bss = .; _bss = .; __bss = .;
*(.bss)
. = ALIGN(4096);
}

end = .; _end = .; __end = .;
}
Post Reply