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 7529ae3a55
636 changed files with 10025 additions and 9387 deletions

15
basic_content/macro/BUILD Normal file
View File

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

Binary file not shown.

View File

@@ -2,75 +2,78 @@
#include <malloc.h>
using namespace std;
#define f1() cout<<"f1()"<<endl;
#define f2() cout<<"f2()"<<endl;
#define f1() cout << "f1()" << endl;
#define f2() cout << "f2()" << endl;
#define fun() {f1();f2();}
#define fun1() \
do{ \
f1();\
f2();\
}while(0)
#define fun() \
{ \
f1(); \
f2(); \
}
#define fun1() \
do { \
f1(); \
f2(); \
} while (0)
int f() {
int *p = (int *)malloc(sizeof(int));
*p = 10;
cout<<*p<<endl;
int *p = (int *)malloc(sizeof(int));
*p = 10;
cout << *p << endl;
#ifndef DEBUG
int error=1;
int error = 1;
#endif
if(error)
goto END;
if (error)
goto END;
// dosomething
// dosomething
END:
cout<<"free"<<endl;
free(p);
return 0;
cout << "free" << endl;
free(p);
return 0;
}
int ff() {
int *p = (int *)malloc(sizeof(int));
*p = 10;
cout<<*p<<endl;
int *p = (int *)malloc(sizeof(int));
*p = 10;
cout << *p << endl;
do{
do {
#ifndef DEBUG
int error=1;
int error = 1;
#endif
if(error)
break;
//dosomething
}while(0);
if (error)
break;
// dosomething
} while (0);
cout<<"free"<<endl;
free(p);
return 0;
cout << "free" << endl;
free(p);
return 0;
}
int fc()
{
int k1 = 10;
cout<<k1<<endl;
do{
int k1 = 100;
cout<<k1<<endl;
}while(0);
cout<<k1<<endl;
int fc() {
int k1 = 10;
cout << k1 << endl;
do {
int k1 = 100;
cout << k1 << endl;
} while (0);
cout << k1 << endl;
return 0;
}
int main() {
if(1>0)
fun();
if (1 > 0)
fun();
if(2>0)
fun1();
if (2 > 0)
fun1();
f();
ff();
fc();
return 0;
f();
ff();
fc();
return 0;
}

Binary file not shown.

View File

@@ -1,7 +1,7 @@
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
@@ -10,77 +10,73 @@ using namespace std;
* (#)字符串操作符
*/
///===========================================
#define exp(s) printf("test s is:%s\n",s)
#define exp1(s) printf("test s is:%s\n",#s)
#define exp2(s) #s
#define exp(s) printf("test s is:%s\n", s)
#define exp1(s) printf("test s is:%s\n", #s)
#define exp2(s) #s
///===========================================
/**
*##)符号连接操作符
*/
///===========================================
#define expA(s) printf("前缀加上后的字符串为:%s\n",gc_##s) //gc_s必须存在
#define expA(s) printf("前缀加上后的字符串为:%s\n", gc_##s) // gc_s必须存在
#define expB(s) printf("前缀加上后的字符串为:%s\n",gc_ ## s) //gc_s必须存在
#define expB(s) printf("前缀加上后的字符串为:%s\n", gc_##s) // gc_s必须存在
#define gc_hello1 "I am gc_hello1"
///===========================================
/**
* (\)续行操作符
*/
///===========================================
#define MAX(a,b) ((a)>(b) ? (a) \
:(b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
int main() {
///===========================================
/**
* (#)字符串操作符
*/
///===========================================
exp("hello");
exp1(hello);
int main() {
///===========================================
/**
* (#)字符串操作符
*/
///===========================================
exp("hello");
exp1(hello);
string str = exp2( bac );
cout<<str<<" "<<str.size()<<endl;
/**
* 忽略传入参数名前面和后面的空格。
*/
string str1 = exp2( asda bac );
/**
* 当传入参数名间存在空格时,编译器将会自动连接各个子字符串,
* 用每个子字符串之间以一个空格连接,忽略剩余空格。
*/
cout<<str1<<" "<<str1.size()<<endl;
string str = exp2(bac);
cout << str << " " << str.size() << endl;
/**
* 忽略传入参数名前面和后面的空格。
*/
string str1 = exp2(asda bac);
/**
* 当传入参数名间存在空格时,编译器将会自动连接各个子字符串,
* 用每个子字符串之间以一个空格连接,忽略剩余空格。
*/
cout << str1 << " " << str1.size() << endl;
///===========================================
/**
* (#)字符串操作符
*/
///===========================================
///===========================================
/**
* (#)字符串操作符
*/
///===========================================
const char * gc_hello = "I am gc_hello";
expA(hello);
expB(hello1);
const char *gc_hello = "I am gc_hello";
expA(hello);
expB(hello1);
char var1_p[20];
char var2_p[20];
char var1_p[20];
char var2_p[20];
// 连接后的实际参数名赋值
strcpy(var1_p, "aaaa");
strcpy(var2_p, "bbbb");
// 连接后的实际参数名赋值
strcpy(var1_p, "aaaa");
strcpy(var2_p, "bbbb");
///===========================================
/**
* (\)续行操作符
*/
///===========================================
int max_val = MAX(3,6);
cout<<max_val<<endl;
return 0;
///===========================================
/**
* (\)续行操作符
*/
///===========================================
int max_val = MAX(3, 6);
cout << max_val << endl;
return 0;
}