'New' Features in C - Dan Saks

preview_player
Показать описание
The first international standard for the C programming language was C90. Since then, three newer standards have been published: C99, C11, and C18. C99 introduced a significant number of new features. C11 introduced a few more, many of which have been available in compilers for some time. C18 fixed bugs in C11 but introduced no new features. Curiously, many of these added features don’t seem to have caught on. Too many C programmers still program in C90 with a sprinkling of C99.

This session explains many of these "new" C features, including inline functions, complex arithmetic, extended integer types, variable-length arrays, flexible array members, compound literals, designated initializers, restricted pointers, type-qualified array parameters, anonymous structures and unions, alignment support, non-returning functions, and static assertions.

Save the date for NDC TechTown 2020 (31st of August - 3rd of September)

Check out more of our talks at:
Рекомендации по теме
Комментарии
Автор

I clicked because I thought this was a classical music composition.

smallerthanlife
Автор

As someone who used to program in C a long time ago, and who's coming back to the language, I found it a very useful presentation. Thanks!

gaius_marius
Автор

Compound literals combined with designated initializers allow to design clear and elegant API styles.

alefratat
Автор

Such a dense material will take ages to digest. Appreciate your work!

NKernytskyy
Автор

37:45 I tried to do just this in godbolt a few days ago. If inline function gets inlined (ex. when using -O3) it will compile and linker won't complain, because there is no function call in the code. If you disable optimizations, function body won't get generated by the compiller (unless you declare it somewhere), but the function call will, and linker will complain. This happens in both GCC and Clang. MSVC doesn't care and just generates the body.

araarathisyomama
Автор

I still prefer C. Been using the newest version whenever possible.

NeilRoy
Автор

If your compiler doesn't support VLAs, you can use alloca to dynamically allocate space on the stack.

jameslay
Автор

ILE/C and C++ on IBM i is a case where there is no integer type that can hold a pointer (ints max out at 64 bits, and pointers (in most cases) are 128 bits.

johnvriezen
Автор

I said to myself, while watching the entirety of the video, "Man, this is a boring video".. Yet it was so interresting that I watched the entirety of it in one sitting

modernkennnern
Автор

The indexing of 2 (or more) dimensional arrays at 49:58 can still use multiple brackets if you use some typecasting voodoo and tell the compiler that it's a higher dimension array:


void example ( int *a, int *b, const int X, const int Y, int number )
{
int (* a_array ) [ X ] = ( int (*) [ X ]) a ;
int (* b_array ) [ X ] = ( int (*) [ X ]) b ;


for ( int j =0; j < Y ; j ++) {
for ( int i =0; i < X ; i ++) {
b_array [ j ][ i ] = a_array [ j ][ i ] + number ;
}
}
}



You'll need to know the dimension size of the inner dimensions in the typecast but it will allow you to avoid the a[i*X+j] calculations. I'm not sure though if C90 will already allow for these typecasts but they've been quite handy for me when working with data allocated elsewhere in the program. From my experience using VLA's in C99 usually gives you data that ends up in stack which is not nice for larger arrays and can result in crashes as already remarked by the audience in the video.

rjordans
Автор

At 47:57 - I wish had known this earlier!

thetdg
Автор

This is a really comprehensive overview with good explanations.
At 17:35 Dan says that a "byte" may be bigger than 8 bits. But I think he talks about a "char". (Or does any of the C or C++ standards refer to "byte"s?)

michaelkotthaus
Автор

Very good presentation - no cap. I think the next slide was about to explain the actual reason for the array parameter syntax - having `static` inside the brackets.

AnFunctionArray
Автор

gcc and clang support a pragma for associating a cleanup function to local pointer variables, provides a poor man's RAII - C community needs to formalize (a cleaner) concept of this into the standard so can be portable across all standards adhering C compilers. Was hoping for discussion about C11 _Generic keyword. what is the ultimate fate of Annex K bounds checking string functions? Any hope of a C library standard for iterating a char or wchar_t string and returning Unicode code points? (Getting code units is only useful for storage calculations - the holy grails is to be able to access strings for code points in portable, standard C manner. C standards folks should not be so lazy and try to tackle some of these issues that really matter and move the needle for working programmers

TheSulross
Автор

I learned a LOT from this video. Thanks 🙏

mohammadmahdifarnia
Автор

Someone know where we can have the slides? I’m curious about the end of it, since it’s a very good talk.

viniciusferrao
Автор

In the next revision of C standard (C23), bool, true and false will be keywords, like in C++.

jcmhprogramming
Автор

Hello Dan Saks, as part of my input/hiring test for some company I've just found that C type(s) like int_least8_t, uint_least8_t, int_least16_t and uint_least16_t are written with small letter 'l', not with capitalised letter 'L'! ;-) But - maybe - of course it could be my misunderstanding/confusing from your choosen font used in your otherwise great presentation.. - On the screen ('flipchart') it appears (to me) as 'tall' (big, capitalised) character.

pavelglosl
Автор

I don't think declaring a volatile flexible array is useless ! It may mean that reading/writing in/out of that array does have side effects, so that no re-ordering/caching is permitted.

ivanscottw
Автор

@11:55: Wouldn't it be safer to compare #if __STDC_VERSION__ >= 201710L ? Otherwise the code will break on a newer compiler, right ?

MichaelFJ