-->
Page 2 of 3

Re: Why can't I access code pointers?

PostPosted: Tue May 12, 2015 9:35 am
by ReinholdHiller
/me too stupid. Sorry. I only get reboots.

Code: Select all  Serial.println((unsigned long )foo,HEX);

  uint32_t ff = (uint32_t)*foo; 
 
  Serial.println(ff,HEX);


(thanks for the fast help.)

Re: Why can't I access code pointers?

PostPosted: Tue May 12, 2015 9:42 am
by jcmvbkbc
Code: Select allint fubar(void) {

  return random(100);
}

void setup() {
  delay(5000);
  Serial.begin(115200);
  char *foo;
  foo=(char *)&fubar;
  Serial.print("Addr: ");
  Serial.println((unsigned long )foo,HEX);
  Serial.print("Value: ");
  Serial.println((byte)*(unsigned long*)foo);     // <-- should not reboot here provided that foo is aligned.
}

Re: Why can't I access code pointers?

PostPosted: Tue May 12, 2015 9:54 am
by ReinholdHiller
But it does.

Addr: 40210834
Value:

ets Jan 8 2013,rst cause:4, boot mode:(1,6)
wdt reset

Re: Why can't I access code pointers?

PostPosted: Tue May 12, 2015 10:13 am
by jcmvbkbc
ReinholdHiller wrote:But it does.

Addr: 40210834
Value:

ets Jan 8 2013,rst cause:4, boot mode:(1,6)
wdt reset

Ok, one more attempt. The compiler gets unexpectedly smart sometimes.
Code: Select allint fubar(void) {

  return random(100);
}

void setup() {
  delay(5000);
  Serial.begin(115200);
  char *foo;
  foo=(char *)&fubar;
  Serial.print("Addr: ");
  Serial.println((unsigned long )foo,HEX);
  Serial.print("Value: ");
  Serial.println((byte)*(volatile unsigned long*)foo);     // <-- does not reboot here provided that foo is aligned.
}