博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C89, C99, C11: All the specifics that I know
阅读量:6182 次
发布时间:2019-06-21

本文共 2572 字,大约阅读时间需要 8 分钟。

before anything.. sizeof is an operand! 

sizeof is an operand!

sizeof is an operand!

重要なことは三回にしませんね!

int *ptr;

sizeof *ptr; = sizeof (int);

--------------the following are the original text------------------

compile in some standard by: -ansi,-std=c99,-std=c11,-std=gnu90,-std=gnu99,-std=gnu11. 

with -pedantic follows the standard strictly.

C89 is called ANSI C..

Starting from C99, we have designated initialization for struct, union and arrarys.. by struct foo foo = {.a=1}; and int a[] = {[2]=3};

Starting from C11, we have the anonymous unions(structs..)

Starting from C99, we have bool(actually _Bool) type, which is not typedefd from char like that in C89, which might causing type conversion problem: (bool) 0x100000000 = false in C89(true in C99?).

Starting from C89, void* can be implicitly converted to any pointer. So in C programming, malloc are conventionally without forced conversion. But in C++, malloc without forced conversion will prompt for warning or even error..

-----updates at 2018.5.8------ after reading torvalds/linux/Documentation/memory-barriers.txt

c11 specifies "memory location": 

A bit-field and an adjacent non-bit-field member are in separate memory locations. The same applies to two bit-fields, if one is declared inside a nested structure declaration and the other is not, or if the two are separated by a zero-length bit-field declaration, or if they are separated by a non-bit-field member declaration. It is not safe to concurrently update two non-atomic bit-fields in the same structure if all members declared between them are also (non-zero-length) bit-fields, no matter what the sizes of those intervening bit-fields happen to be.

It is about avoid race conditions while reading-modify-write of bit-fields. Examples clarified at .

To note that the zero-length bit-field can be defined as:

struct {     char a;    int b:5,     c:2,    d:11,     :0,     e:8;     struct {
int ff:8;} f; }

In the example above, the struct has 4 memory locations: 

1. a

2. b,c,d

3. e

4. f

read-modify-write any one of the memory-location concurrently in threads should apply one and only one mutex.

----------------c++/c function definition difference---

in c, pass by reference can only be the form as:

int func(int *a, struct STR_SOME *p) { *a=1;...; }int a = 0;struct STR_SOME ss;func(&a, &ss);

However, in cpp, you can do the following:

int func(int &a, struct STR_SOME *p) { a=1;...; }int a = 0;struct STR_SOME ss;func(a, &ss); //Now a equals 1 as former

--------------------------------------

转载于:https://www.cnblogs.com/sansna/p/6007193.html

你可能感兴趣的文章
优化源于99%的试验和1%的数据决策力
查看>>
Activiity的四种启动方式(launchMode)
查看>>
你也许不知道的Vuejs - 最佳实践(3)
查看>>
vue-router中scrollBehavior的妙用
查看>>
RSA 算法和另类攻击方式
查看>>
异步处理方案系列- 1.callback
查看>>
设计模式系列之「中介者模式」
查看>>
复杂Vue组件的异步流程分析
查看>>
帝国CMS内核在线听小说听书网源码
查看>>
iOS自定义控件:自定义TableView、CollectionView空数据占位图
查看>>
资深网易技术专家总结的面试高频知识点!
查看>>
你不知道的JavaScript中的数值转换
查看>>
学习Object.assign
查看>>
重庆网易联合创新中心正式开园,29家重庆企业获网易扶持资源
查看>>
重温数据结构系列--二叉树、堆
查看>>
使用 nodejs 写爬虫(二): 抓取 github 热门项目
查看>>
electron 插件系统设计记录
查看>>
12306查票程序
查看>>
java8 lambda 简介
查看>>
为什么前后端分离了,你比从前更痛苦?
查看>>