5 ms·
> IIRC C has an informal guarantee that no primitive syntax will ever cause the CPU to do more than O(1) work at runtime. Assignment is always O(1), and therefo
by jcelerier 4y ago
> IIRC C has an informal guarantee that no primitive syntax will ever cause the CPU to do more than O(1) work at runtime. Assignment is always O(1), and therefore assignment is limited to scalars.
this is absolutely and entirely wrong. You can assign a struct in C and the compiler will call memcpy when you do.
Enjoy: https://godbolt.org/z/98PnhYoev https://godbolt.org/z/98PnhYoev
- wnoise 4y agoAnd any structure is O(1), not O(n), because C structures are not parameterized.
- jcelerier 4y agomemcpy is not O(1)
- LegionMammal978 4y agoIt's O(1) relative to any size computed at runtime: that is, running the same program (with the same array size) on different inputs will always take the same of work for a given assignment.
- jcelerier 4y agoWe're in the context of the assignment operation in the language here. Yes, in C you can only assign statically-known types but that does not mean you can just ignore that a = f(); may take a very different time depending on the types of a and f
- deleted 4y ago[deleted]