Page 1 of 1

Yet another kernel problem YaKP (global variables)

Posted: Wed Feb 04, 2004 11:03 am
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
}

Re:Yet another kernel problem YaKP (global variables)

Posted: Wed Feb 04, 2004 11:12 am
by Therx
Are you loading your DATA section correctly? Or have you written over it by mistake in the program somewhere?

Re:Yet another kernel problem YaKP (global variables)

Posted: Wed Feb 04, 2004 11:25 am
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 = .;
}