๐ข There are some new features in C since I learned it in the 90s. One is variable-length arrays (VLAs). You can now set the length of an array at runtime. This makes some uses of pointers moot, but Linus Torvalds is reported to have said that the Linux kernel does not contain any VLAs.
๐ It may be useful, though. It looks like syntactic sugar for a const pointer plus malloc, but implicitness is usually not ideal. It also appears to use the stack.
๐ข I havenโt looked into the details, but it may be useful in some cases. I donโt think it can replace pointer usage if it uses the stack, though. Stack sizes are usually small, and having arrays that can fill them up is not a good approach. Another feature is complex number support. It seems from the lecture that this is also a bit of a half-baked feature.
๐ What is the difference between this and using a struct with two float fields?
๐ข There are operators (+, -, *, or ==) that support these. Since there is no operator overloading in C, having a separate complex number type may be useful.
๐ The example looks like double complex cx = 1.0 + 3.0*I; and yes, this may be useful if youโre frequently using complex numbers in your code. But I think itโs unnecessary in most cases. There shouldnโt be such a frequent need for complex numbers, right?
๐ข A good complex number library will probably provide more than the built-in type, such as vectors for these numbers. A dedicated library will still be needed in most cases, I believe.
๐ Another feature added to C is that struct members can now be initialized by name or index. You can initialize an array like int a[6] = { [3] = 29, [2] = 14 };, and it will initialize only those specific members.
๐ข Ah, this is much more useful than complex numbers for the general case.
๐ There is also a span syntax: int a[10] = {1, 2, [2 ... 4] = 3, [5] = 30};.
๐ข That is really neat.
๐ Itโs also possible to omit the initial length, so the initializer values determine the size of the array. For example, int a[] = {1, 3, [30] = 55, [9090] = 1010}; will result in an array of length 9091.
๐ข How is this used with structs?
๐ Instead of [], in struct initializers, we use the dot notation, like struct Point p1 = { .x=0, .y=10 };.
๐ข This is really useful and would keep much of the initialization code simpler.
๐ There is also a way to initialize arrays of structs, like:
struct points pts[5] = { [0].x = 10, [0].y = 20, [3].x = 100 };
๐ข This feature is a nice addition to C; I really like it.