Maximum string length in Newlib

6 posts / 0 new
Last post
alfkil
alfkil's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2011-05-10 22:02
Maximum string length in Newlib
Is there a maximum string length for newlib stdio functions? I am getting weird crashes of db101 possibly because of strings of about 12000 bytes in the stabs section... The question is: Is there a limit? How can one know this limit? What is the best workaround for strings longer than this limit?
tboeckel
tboeckel's picture
Offline
Last seen: 2 years 3 months ago
Joined: 2011-09-13 12:32
newlib.library handles C
newlib.library handles C strings only which by definition have no maximum length. The only limit is the trailing NUL byte.
broadblues
broadblues's picture
Offline
Last seen: 2 years 7 months ago
Joined: 2012-05-02 21:48
newlib.library handles C
newlib.library handles C strings only which by definition have no maximum length. The only limit is the trailing NUL byte.
This is true, but ofcourse the string characters must accessed by an array index or some similar. But I would be suprised if newlib was using anything other than signed ints for that internally and even a short would give a max size of '32768'
tboeckel
tboeckel's picture
Offline
Last seen: 2 years 3 months ago
Joined: 2011-09-13 12:32
This is true, but ofcourse
This is true, but ofcourse the string characters must accessed by an array index or some similar.
Wrong. It might look hackish, but in C you can iterate over a string without any kind of integer index. You just have to manipulate a pointer. For example:
  1. char *p = string;
  2. while(*p != '\0')
  3. p++
This will go to the end of the string, no matter how long it is, and without any kind of index.
alfkil
alfkil's picture
Offline
Last seen: 1 year 1 month ago
Joined: 2011-05-10 22:02
Thanks for the answers, turns
Thanks for the answers, turns out, that the problem was caused by something completely different... Next time, I will use the DebugPrintF properly, so I don't end up thinking something not right about the cause of my problems...
hypex
hypex's picture
Offline
Last seen: 6 days 21 hours ago
Joined: 2011-09-09 16:20
@alfkil Maybe next time you
@alfkil Maybe next time you can use DB101 also. Very useful tool! :-P
Log in or register to post comments