bugAVR C Runtime Library - Bugs: bug #31613, In pgm_read_byte the address is a...

 
 

bug #31613: In pgm_read_byte the address is a byte instead of an int

Submitted by:  Reinier van der Welle <reinier>
Submitted on:  Wed 10 Nov 2010 02:23:52 PM UTC  
 
Category: LibrarySeverity: 3 - Normal
Priority: 5 - NormalItem Group: libc code
Status: InvalidPercent Complete: 0%
Assigned to: NoneOpen/Closed: Closed
Release: 1.6.7Fixed Release: None

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Wed 10 Nov 2010 04:30:00 PM UTC, comment #4:

I apologize for having bothered you; I am too much a newbie, I fear. I was not aware of avr-gcc-list (did not see it in the docs up till now).

I was confused about the pointer, supposing that it was 8 bits wide.

Anyway, thanks a lot for your help. I will stick now to avr-gcc-list.

Reinier van der Welle <reinier>
Wed 10 Nov 2010 04:07:22 PM UTC, comment #3:

> but I cannot see an error in the attached example.


The error is:

unsigned int *ptab;

Make this:

unsigned char *ptab;

and it will work as expected. The pointer points to a
"char" object, yet the pointer itself (i.e., the temporary
variable "ptab") is 16 bits wide anyway.

Despite, useless use of a pointer variable.

j = pgm_read_byte(testtab + yy);

would work without problems, as would

j = pgm_read_byte(&testtab[yy]);

Please, use the avr-gcc-list for that kind of questions.

Joerg Wunsch <joerg_wunsch>
Project Administrator
Wed 10 Nov 2010 03:45:10 PM UTC, comment #2:

Thanks for your comment, but I cannot see an error in the attached example. When the code is run and j is watched, it gets the values 10, 8, 6, 4 end so on, instead of 10, 9, 8 ,7 ... See also the compiler warning "assignment from incompatible pointer type". When the char pointer is used, all is OK (of course). But the address of the table could be well beyond $FF (the maximum of the char pointer).
Where do I miss the point?
Reinier

(file #21976)

Reinier van der Welle <reinier>
Wed 10 Nov 2010 02:37:17 PM UTC, comment #1:

You are confusing the pointer with the object it points to:
the object is 8 bits wide, but the pointer is 16 bits.

Joerg Wunsch <joerg_wunsch>
Project Administrator
Wed 10 Nov 2010 02:23:52 PM UTC, original submission:

I am trying to use pgm_read_byte(address) for reading a byte from tables in program flash. The compiler requires a char (byte) address instead of an int (16 bits) (which should be the case according to the documentation). Using an int address skips every second byte in the table. How can I use int addresses?
Thank you for your comments.
Reinier

Reinier van der Welle <reinier>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

Attached Files
file #21976:  readbyte.zip added by reinier (7KiB - application/x-zip-compressed)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by joerg_wunsch (Posted a comment)
  • -unavailable- added by reinier (Submitted the item)
  • -unavailable- added by reinier
  •  

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 10 Nov 2010 03:45:10 PM UTCreinierAttached File-=>Added readbyte.zip, #21976
    Wed 10 Nov 2010 02:37:31 PM UTCjoerg_wunschOpen/ClosedOpen=>Closed
    Wed 10 Nov 2010 02:37:17 PM UTCjoerg_wunschStatusNone=>Invalid
    Wed 10 Nov 2010 02:23:52 PM UTCreinierCarbon-Copy-=>Added reinier

    Back to the top


    Powered by Savane 3.1-cleanup1