Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
tus88
on Sept 12, 2020
|
parent
|
context
|
favorite
| on:
C’s Biggest Mistake (2009)
> Conflating pointers with arrays.
AND Strings.
FTFY.
yarrel
on Sept 12, 2020
[–]
C doesn't have strings. ;-)
Snarwin
on Sept 12, 2020
|
parent
|
next
[–]
More precisely, it doesn't have a string
type
.
Skunkleton
on Sept 12, 2020
|
root
|
parent
|
next
[–]
It certainly has string literals, which are a kind of type.
mark-r
on Sept 13, 2020
|
root
|
parent
|
next
[–]
That's the thing, they're not a type - they're just an array of char with an unspecified length, indistinguishable from any other array of char or pointer to char. Only the convention of ending them with a null character makes them usable at all.
Skunkleton
on Sept 13, 2020
|
root
|
parent
|
next
[–]
printf("%lu\n", sizeof("Well, actshully")); -> 16
rightbyte
on Sept 13, 2020
|
root
|
parent
|
next
[–]
One could say that C has a different type for each string size plus the joker pointer to char.
tus88
on Sept 13, 2020
|
parent
|
prev
[–]
That's because they were conflated with both arrays and pointers.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search:
AND Strings.
FTFY.