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

 
 

You are not allowed to post comments on this tracker with your current authentication level.

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

Submitter:  Reinier van der Welle <reinier>
Submitted:  Wed 10 Nov 2010 02:23:52 PM UTC
   
 
Category:  Library Severity:  3 - Normal
Priority:  5 - Normal Item Group:  libc code
Status:  Invalid Assigned to:  None
Percent Complete:  0% Open/Closed:  Closed
Release:  1.6.7 Fixed Release:  None

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>
Group 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>
Group 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.)

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
  • -email is unavailable- added by joerg_wunsch (Posted a comment)
  • -email is unavailable- added by reinier (Submitted the item)
  • -email is unavailable- added by reinier
  •  

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2010-11-10 reinier Attached File- Added readbyte.zip, #21976
    2010-11-10 joerg_wunsch Open/ClosedOpen Closed
    2010-11-10 joerg_wunsch StatusNone Invalid
    2010-11-10 reinier Carbon-Copy- Added reinier

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code