C, Fortran, and single-character strings
C, Fortran, and single-character strings
Posted Jun 22, 2019 21:37 UTC (Sat) by marcH (subscriber, #57642)In reply to: C, Fortran, and single-character strings by ncm
Parent article: C, Fortran, and single-character strings
> 'Cause I could list such, all day long, about any system, language, or technology you can think of.
Sure, let's start by looking at some CVE statistics. Wait, I said no digression sorry.
Posted Jun 23, 2019 4:04 UTC (Sun)
by Cyberax (✭ supporter ✭, #52523)
[Link] (3 responses)
C strings allow you to pass substrings as a pair of pointers (or just one pointer for tail substrings), for example.
Posted Jun 23, 2019 18:02 UTC (Sun)
by marcH (subscriber, #57642)
[Link] (2 responses)
Yes the type of (safer) arrays would have been one step above "primitive".
Looking at string.h on opengroup.org, it's interesting to see almost half the functions there already have some size_t argument.
> C strings allow you to pass substrings as a pair of pointers (or just one pointer for tail substrings), for example.
This is indeed a performance optimization. It's also a dangerous one if the array is not const (who owns it now?) and I don't see how "higher level" arrays would stop you from still doing that, I would just discourage you from doing it routinely in non-critical paths.
Posted Jun 23, 2019 21:07 UTC (Sun)
by Cyberax (✭ supporter ✭, #52523)
[Link] (1 responses)
I'm not saying that it's a good idea now, but null-terminated strings certainly make sense in C.
Posted Jun 25, 2019 16:41 UTC (Tue)
by rgmoore (✭ supporter ✭, #75)
[Link]
No. A language with only safe arrays won't be C. C is supposed to provide access to low-level functions and that includes unsafe pointers and arrays. But C is also supposed to allow programmers to build higher-level abstractions, including things like safe arrays and strings, and there's excellent reason to use those safe arrays and strings in place of the unsafe alternatives when performance is not critical.
C, Fortran, and single-character strings
C, Fortran, and single-character strings
C, Fortran, and single-character strings
Sure, but C was designed without such arrays. And a language with safe arrays won't be C.
C, Fortran, and single-character strings
Sure, but C was designed without such arrays. And a language with safe arrays won't be C.