Free pascal pointer record array2/1/2024 C and the its standards therefore deprecated the old string use, and now use "-n-" versions of the older string routines (strNcpy etc) that need a maximal length to be passed. More importantly, since the early nineties security became more important, and in general solely relying on null terminated strings property is frowned upon because small errors in validation can cause potentially exploitable buffer overflow issues. Nowadays optimizing compilers could easily detect any of these constructs and convert them to whatever is best. In case of an architecture that had built in post increment (++) operators (like the PDP-8,11's C was developed for originally), the pointer version was even cheaper, specially without optimization. Additionally, UCSD was a bytecode (p-code) interpreter language, and the latter code based on pascal string use is "safe". This made the number of instructions in a Pascal string loop slightly larger than the equivalent zero terminated string, and adds one more live value. While (i<=len) do begin p:=p2 inc(i) end while (len>0) do begin p^:=p2^ inc(p) inc(p2) dec(len) end Which is wholly equivalent to while (*s++ = *t++) So instead by copying a string using while (p^) do begin P^=p2^ inc(p) inc(p2) end On the other hand, this means that in a loop, you need some additional check based on indexes to check for the end of the string. While the construct is not part of Standard Pascal, the most popular dialects from Borland (Turbo Pascal, Delphi and Free Pascal) generally base themselves on UCSD dialect, and thus have pascal strings, Delphi currently has 5 such strings. Moreover, since software was mostly used in isolation, all kinds of schemes were used, often based on what was advantageous for that implementation/architecture. IIRC, the original (seventies) convention was to space pad an allocation, and scan backwards for a non space character (making it impossible for strings to have a terminating space). This makes getting the length a constant time operation (O(1)) instead of scanning the character data for a nul character. In general it is not one specific type, but the basic principle of having the size prefixed to the character data. This is the same implementation that made bytecode interpreters popular. Pascal strings were made popular by one specific, but huge influential Pascal implementation, named UCSD.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |