Skip to content

Instantly share code, notes, and snippets.

@domiyanyue
domiyanyue / hello.cpp
Created April 22, 2020 03:06
Example hello.cpp
#include <iostream>
int main(){
std::cout << "Hello World";
return 0;
}
@domiyanyue
domiyanyue / compile_1.sh
Last active April 24, 2020 00:25
compile simple
g++ hello.cpp -o hello
./hello
Hello World
@domiyanyue
domiyanyue / warning_example.cpp
Last active April 23, 2020 18:32
c++ warning example
int main(){
int a = 1;
return 0;
}
cpp_tutorial# g++ warning_example.cpp -Wall -o a
warning_example.cpp: In function ‘int main()’:
warning_example.cpp:2:9: warning: unused variable ‘a’ [-Wunused-variable]
int a = 1;
^
@domiyanyue
domiyanyue / warning_example_uninitialized.cpp
Last active April 23, 2020 18:56
Warning -Wunused-function example
int main(){
int array[100];
return array[1];
}
cpp_tutorial# g++ warning_example.cpp -Wuninitialized -o a -Werror
warning_example.cpp: In function ‘int main()’:
warning_example.cpp:4:19: error: ‘array[1]’ is used uninitialized in this function [-Werror=uninitialized]
return array[1];
^
cc1plus: all warnings being treated as errors
@domiyanyue
domiyanyue / macro_compile.cpp
Last active December 22, 2020 05:46
example -D macro
#include <iostream>
#ifndef SIZE_ARRAY
#define SIZE_ARRAY 4
#endif
int main(){
int array[SIZE_ARRAY] = {0};
std::cout << "num of elements: " << sizeof(array)/sizeof(array[0]) << "\n";
return 0;
}
@domiyanyue
domiyanyue / main.cpp
Created April 25, 2020 02:55
example_include
#include "vars.h"
int main(){
return 0;
}
@domiyanyue
domiyanyue / main.cpp
Created April 25, 2020 03:04
example_after_include
int a = 1;
int foo(){
return 2;
}
int main(){
return 0;
}
@domiyanyue
domiyanyue / 1_run.txt
Last active April 26, 2020 00:32
preprocessing example
g++ -E example.cpp -o _preprocess.out