[HN Gopher] C's Biggest Mistake
___________________________________________________________________
C's Biggest Mistake
Author : fzliu
Score : 31 points
Date : 2023-07-02 19:00 UTC (4 hours ago)
(HTM) web link (www.digitalmars.com)
(TXT) w3m dump (www.digitalmars.com)
| fithisux wrote:
| One of the best tech articles in 2009. Short and to the point.
| fithisux wrote:
| 14 years later nothing is fixed. But we still have D and an
| array of new developer friendly languages.
| psychoslave wrote:
| Sure, but I don't see any of them even pretending to be a C
| replacement.
|
| I wonder if in several thousands year, mankind will have
| managed to get rid of C.
| 2h wrote:
| Go did fix the C mistake: package main
| func foo(a []byte) { println(len(a)) }
| func main() { var b []byte // cannot use &b
| (value of type *[]byte) as []byte value in argument to foo
| foo(&b) }
| NoZZz wrote:
| [flagged]
| joshuaissac wrote:
| > I mean the inability to pass an array to a function as an
| array, even if it is declared to be an array.
|
| This is possible for fixed-length arrays using 'myType
| (*myVar)[size]' as the argument type.
|
| https://stackoverflow.com/a/51527502
| chongli wrote:
| But in reality is of limited utility. This fixes the size of
| the array in the function signature. If I want to write a
| function that returns the sum of all the integers in an array I
| would need to write a new function for each size of array, a
| non-starter.
|
| The annoying thing about this is that the array is just sitting
| there on the stack of the calling function. The size is
| completely known at compile time. But it gets thrown away as
| soon as you call a function.
| a_nop wrote:
| Supplying the array length to such a summing function is not
| a big deal. The compiler is not likely to handle this poorly.
| Probably gets inlined.
|
| If the syntax is the problem, yeah, if you want first class
| data structures you might not like C.
___________________________________________________________________
(page generated 2023-07-02 23:00 UTC)