Is this mistake at: 6.17.1 AVR Named Address Spaces?

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi - I was reading the info at https://gcc.gnu.org/onlinedocs/gcc/Named-Address-Spaces.html

It is written:

char my_read (const __flash char ** p)
{
    /* p is a pointer to RAM that points to a pointer to flash.
       The first indirection of p reads that flash pointer
       from RAM and the second indirection reads a char from this
       flash address.  */

    return **p;
}

/* Locate array[] in flash memory */
const __flash int array[] = { 3, 5, 7, 11, 13, 17, 19 };

int i = 1;

int main (void)
{
   /* Return 17 by reading from flash memory */
   return array[array[i]];
}

Should this not read - Return 7 by reading from flash memory?? (Not 17)

Last Edited: Tue. Aug 6, 2019 - 09:25 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

array[array[1]] is

array[5] which is

17

 

So it's correct.

 

(and I moved this to a more appropriate forum)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok - got it. thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yep, I'll NEVER understand pointers I'm afraid!!! sad I would have said the return is 5.....

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A tricky puzzle!

The largest known prime number: 282589933-1

It's easy to stop breaking the 10th commandment! Break the 8th instead. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I find it easiest to work outward from the inner-most parenthesis.

 

i=1

so

array[i] = array[1] = 5

then 

 

array[array[i]] = array[array[1]] = array[5] = 17

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's the old is the first element really element zero conundrum  ...don't leave it to a coin toss, you need to know for certain for your language/package.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not that I'm really that interested anymore cheeky Like Harry Belafonte used to sing

.

.

.

But now that I am ninety three
I don't give a darn you see

If the woman piaba and the man piaba
And the Ton Ton call baka lemon grass,
The lily root, gully root, belly root uhmm,
And the famous grandy scratch scratch

 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:
Yep, I'll NEVER understand pointers I'm afraid!!!
Just as well they aren't involved here then?

 

It's simply about array indexing.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

C for Everyone | The Ganssle Group

...

Newbies always get fouled up with pointers, but C for Everyone has a great chapter on the subject. I also recommend Understanding and Using C Pointers by Richard Reese

...

"C 4 Everyone" Book (Imagecraft Creations)

ISBN 9781449344184 - Understanding and Using C Pointers: Core Techniques for Memory Management

 

"Dare to be naïve." - Buckminster Fuller