support bazel complie this project and format code.

This commit is contained in:
zhangxing
2023-03-30 00:15:11 +08:00
committed by light-city
parent 1f86192576
commit 3c8a3f259b
641 changed files with 10349 additions and 9523 deletions

View File

@@ -0,0 +1,15 @@
# please run `bazel run basic_content/volatile:noopt_vola`
# please run `bazel run basic_content/volatile:volatile`
load("@rules_cc//cc:defs.bzl", "cc_binary")
cc_binary(
name = "noopt_vola",
srcs = ["noopt_vola.cpp"],
copts = ["-std=c++11"]
)
cc_binary(
name = "volatile",
srcs = ["volatile.cpp"],
copts = ["-std=c++11"]
)

View File

@@ -80,7 +80,7 @@ void threadFunc2()
可以。一个例子是只读的状态寄存器。它是volatile因为它可能被意想不到地改变。它是const因为程序不应该试图去修改它。
2一个指针可以是volatile吗为什么
可以。尽管这并不常见。一个例子是当一个中断服务子程序修一个指向一个buffer的指针时。
可以。尽管这并不常见。一个例子是当一个中断服务子程序修一个指向一个buffer的指针时。
3下面的函数有什么错误
```c++

View File

@@ -1,15 +1,14 @@
/* Compile code without optimization option */
#include <stdio.h>
int main(void)
{
const int local = 10;
int *ptr = (int*) &local;
#include <stdio.h>
int main(void) {
const int local = 10;
int *ptr = (int *)&local;
printf("Initial value of local : %d \n", local);
printf("Initial value of local : %d \n", local);
*ptr = 100;
*ptr = 100;
printf("Modified value of local: %d \n", local);
printf("Modified value of local: %d \n", local);
return 0;
}
return 0;
}

Binary file not shown.

View File

@@ -1,16 +1,15 @@
/* Compile code with optimization option */
#include <stdio.h>
#include <stdio.h>
int main(void)
{
const volatile int local = 10;
int *ptr = (int*) &local;
int main(void) {
const volatile int local = 10;
int *ptr = (int *)&local;
printf("Initial value of local : %d \n", local);
printf("Initial value of local : %d \n", local);
*ptr = 100;
*ptr = 100;
printf("Modified value of local: %d \n", local);
printf("Modified value of local: %d \n", local);
return 0;
}
return 0;
}