프로그램 사용/gcc2017. 6. 20. 09:49

매크로에도 ...을 쓸 수 있다니 ㄷㄷ


#define eprintf() fprintf (stderr, __VA_ARGS__)

[링크 : https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html]

'프로그램 사용 > gcc' 카테고리의 다른 글

c large file support  (0) 2019.06.21
gcc5 atoi / stoi  (0) 2019.06.14
문자열에 escape 로 특수문자 넣기  (0) 2017.06.19
gcc cpp type (유니코드 문자열)  (0) 2017.04.04
gcc 매크로 확장 define stringfication  (0) 2017.01.02
Posted by 구차니
프로그램 사용/gcc2017. 6. 19. 22:10

"\x6E" 이런식으로 문자를 넣으면 되는데 연속으로 넣으면 에러날수도(?)

만약에


0xc0 À 를 넣으면

"\xC0" 인데

À1 을 출력하고 싶다고

"\xC01"을 넣으면 이상한 걸로 인식을 하거나 에러나기도 한다.


어떻게 해결 해야 하려나...


\nnnnote 1anyThe byte whose numerical value is given by nnn interpreted as an octal number
\xhh…anyThe byte whose numerical value is given by hh… interpreted as a hexadecimal number
\enote 21Bescape character (some character sets)
\Uhhhhhhhhnote 3noneUnicode code point where h is a hexadecimal digit
\uhhhhnote 4noneUnicode code point below 10000 hexadecimal

[링크 : https://en.wikipedia.org/wiki/Escape_sequences_in_C]

'프로그램 사용 > gcc' 카테고리의 다른 글

gcc5 atoi / stoi  (0) 2019.06.14
gcc variadic macro  (0) 2017.06.20
gcc cpp type (유니코드 문자열)  (0) 2017.04.04
gcc 매크로 확장 define stringfication  (0) 2017.01.02
gcc make CFLAGS=-D 관련  (0) 2016.11.17
Posted by 구차니
프로그램 사용/gcc2017. 4. 4. 21:00

GCC G++ 공식문서를 찾지 못했는데

아무튼.. wchar_t 로 wide character형이 추가된것 외에는 차이가 없는듯

kldp 쪽을 봐도 gcc에서는 UTF-32 4byte 로 된다는 정도만 있는것 봐서는

MSVC에 비해 유니코드 대응이 미진하긴 미진 한 듯.


wchar_t

type for wide character representation (see wide strings). Required to be large enough to represent any supported character code point (32 bits on systems that support Unicode. A notable exception is Windows, where wchar_t is 16 bits and holds UTF-16 code units) It has the same size, signedness, and alignment as one of the integral types, but is a distinct type.


[링크 : http://en.cppreference.com/w/cpp/language/types]

[링크 : http://en.cppreference.com/w/cpp/keyword]

'프로그램 사용 > gcc' 카테고리의 다른 글

gcc variadic macro  (0) 2017.06.20
문자열에 escape 로 특수문자 넣기  (0) 2017.06.19
gcc 매크로 확장 define stringfication  (0) 2017.01.02
gcc make CFLAGS=-D 관련  (0) 2016.11.17
gcc -fPIC  (0) 2016.06.22
Posted by 구차니
프로그램 사용/gcc2017. 1. 2. 15:14

'프로그램 사용 > gcc' 카테고리의 다른 글

문자열에 escape 로 특수문자 넣기  (0) 2017.06.19
gcc cpp type (유니코드 문자열)  (0) 2017.04.04
gcc make CFLAGS=-D 관련  (0) 2016.11.17
gcc -fPIC  (0) 2016.06.22
gcc dependency .d 파일?  (0) 2016.03.28
Posted by 구차니
프로그램 사용/gcc2016. 11. 17. 17:43

-D 는 아는데..

-DFLAG=1 이런식으로 쓰는걸 몰라서 검색 ㅠㅠ


-D name

Predefine name as a macro, with definition 1. 

-D name=definition

The contents of definition are tokenized and processed as if they appeared during translation phase three in a ‘#define’ directive. In particular, the definition will be truncated by embedded newline characters.

If you are invoking the preprocessor from a shell or shell-like program you may need to use the shell's quoting syntax to protect characters such as spaces that have a meaning in the shell syntax.


If you wish to define a function-like macro on the command line, write its argument list with surrounding parentheses before the equals sign (if any). Parentheses are meaningful to most shells, so you will need to quote the option. With sh and csh, -D'name(args...)=definition' works.


-D and -U options are processed in the order they are given on the command line. All -imacros file and -include file options are processed after all -D and -U options.  

[링크 : https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html]

[링크 : https://wiki.openssl.org/index.php/Manual:OPENSSL_VERSION_NUMBER(3)]

'프로그램 사용 > gcc' 카테고리의 다른 글

gcc cpp type (유니코드 문자열)  (0) 2017.04.04
gcc 매크로 확장 define stringfication  (0) 2017.01.02
gcc -fPIC  (0) 2016.06.22
gcc dependency .d 파일?  (0) 2016.03.28
gcc -M -MM  (0) 2015.12.17
Posted by 구차니
프로그램 사용/gcc2016. 6. 22. 12:25

-f 니까 플래그고

PIC(Position Independent Code)

[링크 : http://devanix.tistory.com/198]


-shared 하면 자동으로 -fpic나 -fPIC가 설정되는건 아닌듯?

아무튼. .x86에는 연관이 없지만, 다른 아키텍쳐에서는 GOT 크기 문제로 -fpic와 -fPIC가 다르게 적용된다고 한다.

-shared

Produce a shared object which can then be linked with other objects to form an executable. Not all systems support this option. For predictable results, you must also specify the same set of options that were used to generate code (-fpic, -fPIC, or model suboptions) when you specify this option.[1]


-fpic

Generate position-independent code ( PIC ) suitable for use in a shared library, if supported for the target machine. Such code accesses all constant addresses through a global offset table ( GOT ). The dynamic loader resolves the GOT entries when the program starts (the dynamic loader is not part of GCC ; it is part of the operating system). If the GOT size for the linked executable exceeds a machine-specific maximum size, you get an error message from the linker indicating that -fpic does not work; in that case, recompile with -fPIC instead. (These maximums are 8k on the SPARC and 32k on the m68k and RS/6000 . The 386 has no such limit.)

Position-independent code requires special support, and therefore works only on certain machines. For the 386, GCC supports PIC for System V but not for the Sun 386i. Code generated for the IBM RS/6000 is always position-independent.


When this flag is set, the macros "__pic__" and "__PIC__" are defined to 1.


-fPIC

If supported for the target machine, emit position-independent code, suitable for dynamic linking and avoiding any limit on the size of the global offset table. This option makes a difference on the m68k, PowerPC and SPARC .

Position-independent code requires special support, and therefore works only on certain machines.


When this flag is set, the macros "__pic__" and "__PIC__" are defined to 2.


-fpie

-fPIE

These options are similar to -fpic and -fPIC, but generated position independent code can be only linked into executables. Usually these options are used when -pie GCC option will be used during linking.

-fpie and -fPIE both define the macros "__pie__" and "__PIE__". The macros have the value 1 for -fpie and 2 for -fPIE. 

[링크 : http://linux.die.net/man/1/gcc]




Pseudo-assembly:


PIC: This would work whether the code was at address 100 or 1000

100: COMPARE REG1, REG2

101: JUMP_IF_EQUAL CURRENT+10

...

111: NOP


Non-PIC: This will only work if the code is at address 100

100: COMPARE REG1, REG2

101: JUMP_IF_EQUAL 111

...

111: NOP


If your code is compiled with -fPIC, it's suitable for inclusion in a library - the library must be able to be relocated from its preferred location in memory to another address, there could be another already loaded library at the address your library prefers. 

[링크 : http://stackoverflow.com/questions/5311515/gcc-fpic-option?rq=1]

'프로그램 사용 > gcc' 카테고리의 다른 글

gcc 매크로 확장 define stringfication  (0) 2017.01.02
gcc make CFLAGS=-D 관련  (0) 2016.11.17
gcc dependency .d 파일?  (0) 2016.03.28
gcc -M -MM  (0) 2015.12.17
gcc 초기화 관련  (0) 2015.10.21
Posted by 구차니
프로그램 사용/gcc2016. 3. 28. 20:21

쓰는 법은 좀 나중에 읽어 봐야지...

make + gcc에서

컴파일시 의존성을 자동으로 끌어가기 위해

(make 쪽에서 파일 의존성 체크 하니까)

gcc를 이용하여 해당 소스에서 요구하는 헤더들의 목록을 .d 파일로 빼내는 기능


-MM 등의 옵션이 있나 보다..


[링크 : https://latedev.wordpress.com/2014/11/08/generic-makefiles-with-gcc-and-gnu-make/]

[링크 : http://scottmcpeak.com/autodepend/autodepend.html]

[링크 : https://gcc.gnu.org/onlinedocs/gcc-4.4.1/gcc/Preprocessor-Options.html]

'프로그램 사용 > gcc' 카테고리의 다른 글

gcc make CFLAGS=-D 관련  (0) 2016.11.17
gcc -fPIC  (0) 2016.06.22
gcc -M -MM  (0) 2015.12.17
gcc 초기화 관련  (0) 2015.10.21
precompiled header on GCC (라즈베리로 테스트)  (2) 2015.07.30
Posted by 구차니
프로그램 사용/gcc2015. 12. 17. 17:13

-E는 프리프로세서를 거친 결과를 뽑아준다면..

-M은 확장된 헤더의 목록만 빼준다.


-E

Stop after the preprocessing stage; do not run the compiler proper. The output is in the form of preprocessed source code, which is sent to the standard output.


-M

Instead of outputting the result of preprocessing, output a rule suitable for make describing the dependencies of the main source file. The preprocessor outputs one make rule containing the object file name for that source file, a colon, and the names of all the included files, including those coming from -include or -imacros command line options.


Unless specified explicitly (with -MT or -MQ), the object file name consists of the name of the source file with any suffix replaced with object file suffix and with any leading directory parts removed. If there are many included files then the rule is split into several lines using \-newline. The rule has no commands.

This option does not suppress the preprocessor's debug output, such as -dM. To avoid mixing such debug output with the dependency rules you should explicitly specify the dependency output file with -MF, or use an environment variable like DEPENDENCIES_OUTPUT . Debug output will still be sent to the regular output stream as normal.


Passing -M to the driver implies -E, and suppresses warnings with an implicit -w.


-MM

Like -M but do not mention header files that are found in system header directories, nor header files that are included, directly or indirectly, from such a header.


This implies that the choice of angle brackets or double quotes in an #include directive does not in itself determine whether that header will appear in -MM dependency output. This is a slight change in semantics from GCC versions 3.0 and earlier.


[링크 : http://linux.die.net/man/1/gcc]

'프로그램 사용 > gcc' 카테고리의 다른 글

gcc -fPIC  (0) 2016.06.22
gcc dependency .d 파일?  (0) 2016.03.28
gcc 초기화 관련  (0) 2015.10.21
precompiled header on GCC (라즈베리로 테스트)  (2) 2015.07.30
gcc에서 precompiled header 사용하기  (0) 2015.07.29
Posted by 구차니
프로그램 사용/gcc2015. 10. 21. 11:33

C99 관련추가 내용인가?

일단은 GCC-2.5 이후 부터 지원하는 기능으로 보인다.

2009/05/28 - [Programming/C / Win32 / MFC] - C99 구조체 초기화 하기


5.22 Designated Initializers


Standard C89 requires the elements of an initializer to appear in a fixed order, the same as the order of the elements in the array or structure being initialized.


In ISO C99 you can give the elements in any order, specifying the array indices or structure field names they apply to, and GNU C allows this as an extension in C89 mode as well. This extension is not implemented in GNU C++.


To specify an array index, write `[index] =' before the element value. For example,


 

int a[6] = { [4] = 29, [2] = 15 };


is equivalent to


 

int a[6] = { 0, 0, 15, 0, 29, 0 };


The index values must be constant expressions, even if the array being initialized is automatic.


An alternative syntax for this which has been obsolete since GCC 2.5 but GCC still accepts is to write `[index]' before the element value, with no `='.


To initialize a range of elements to the same value, write `[first ... last] = value'. This is a GNU extension. For example,


 

int widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };


If the value in it has side-effects, the side-effects will happen only once, not for each initialized field by the range initializer.


Note that the length of the array is the highest value specified plus one.


In a structure initializer, specify the name of a field to initialize with `.fieldname =' before the element value. For example, given the following structure,


 

struct point { int x, y; };


the following initialization


 

struct point p = { .y = yvalue, .x = xvalue };


is equivalent to


 

struct point p = { xvalue, yvalue };


Another syntax which has the same meaning, obsolete since GCC 2.5, is `fieldname:', as shown here:


 

struct point p = { y: yvalue, x: xvalue };


The `[index]' or `.fieldname' is known as a designator. You can also use a designator (or the obsolete colon syntax) when initializing a union, to specify which element of the union should be used. For example,


 

union foo { int i; double d; };


union foo f = { .d = 4 };


will convert 4 to a double to store it in the union using the second element. By contrast, casting 4 to type union foo would store it into the union as the integer i, since it is an integer. (See section 5.24 Cast to a Union Type.)


You can combine this technique of naming elements with ordinary C initialization of successive elements. Each initializer element that does not have a designator applies to the next consecutive element of the array or structure. For example,


 

int a[6] = { [1] = v1, v2, [4] = v4 };


is equivalent to


 

int a[6] = { 0, v1, v2, 0, v4, 0 };


Labeling the elements of an array initializer is especially useful when the indices are characters or belong to an enum type. For example:


 

int whitespace[256]

  = { [' '] = 1, ['\t'] = 1, ['\h'] = 1,

      ['\f'] = 1, ['\n'] = 1, ['\r'] = 1 };


You can also write a series of `.fieldname' and `[index]' designators before an `=' to specify a nested subobject to initialize; the list is taken relative to the subobject corresponding to the closest surrounding brace pair. For example, with the `struct point' declaration above:


 

struct point ptarray[10] = { [2].y = yv2, [2].x = xv2, [0].x = xv0 };


If the same field is initialized multiple times, it will have value from the last initialization. If any such overridden initialization has side-effect, it is unspecified whether the side-effect happens or not. Currently, gcc will discard them and issue a warning.


[링크 : https://gcc.gnu.org/onlinedocs/gcc-3.0.1/gcc_5.html]

'프로그램 사용 > gcc' 카테고리의 다른 글

gcc dependency .d 파일?  (0) 2016.03.28
gcc -M -MM  (0) 2015.12.17
precompiled header on GCC (라즈베리로 테스트)  (2) 2015.07.30
gcc에서 precompiled header 사용하기  (0) 2015.07.29
gcc 64bit 변수 선언하기  (0) 2015.07.14
Posted by 구차니
프로그램 사용/gcc2015. 7. 30. 10:10

-c -o gch를 통해서 gcc precompiled header를 생성이 가능하다.

물론 gch가 생성되면 원래 헤더파일이 사라져도 문제없이 컴파일 된다.

pi@raspberrypi ~/src/pch $ g++ -c stdafx.h -o stdafx.h.gch


pi@raspberrypi ~/src/pch $ ls -al

합계 4244

drwxr-xr-x 2 pi pi    4096  7월 30 00:58 .

drwxr-xr-x 9 pi pi    4096  7월 30 00:58 ..

-rw-r--r-- 1 pi pi      37  7월 30 00:58 1

-rw-r--r-- 1 pi pi      91  7월 30 00:58 a.cpp

-rw-r--r-- 1 pi pi      37  7월 30 00:58 stdafx.h

-rw-r--r-- 1 pi pi 4324036  7월 30 00:59 stdafx.h.gch


pi@raspberrypi ~/src/pch $ file stdafx.h.gch

stdafx.h.gch: GCC precompiled header (version 013) for C++


pi@raspberrypi ~/src/pch $ mv stdafx.h stdafx.h.bak

pi@raspberrypi ~/src/pch $ g++ a.cpp 


확장자 gch로 확인하기 때문에 다른 확장자로 변경시 gch 헤더를 찾지 못한다.

pi@raspberrypi ~/src/pch $ mv stdafx.h.gch stdafx.h.gch.bak

pi@raspberrypi ~/src/pch $ ls -al

합계 4248

drwxr-xr-x 2 pi pi    4096  7월 30 01:01 .

drwxr-xr-x 9 pi pi    4096  7월 30 00:58 ..

-rw-r--r-- 1 pi pi      91  7월 30 00:58 a.cpp

-rwxr-xr-x 1 pi pi    6492  7월 30 01:00 a.out

-rw-r--r-- 1 pi pi      37  7월 30 00:58 stdafx.h.bak

-rw-r--r-- 1 pi pi 4324036  7월 30 00:59 stdafx.h.gch.bak

pi@raspberrypi ~/src/pch $ g++ a.cpp

a.cpp:1:20: fatal error: stdafx.h: 그런 파일이나 디렉터리가 없습니다

compilation terminated.


-c가 좀더 간편한듯.

-x c++-hedaer

-x c-header는 너무 길어 -_-

pi@raspberrypi ~/src/pch $ gcc -x c++-header stdafx.h -o stdafx.h.gch

pi@raspberrypi ~/src/pch $ ls -al

합계 4248

drwxr-xr-x 2 pi pi    4096  7월 30 01:01 .

drwxr-xr-x 9 pi pi    4096  7월 30 00:58 ..

-rw-r--r-- 1 pi pi      91  7월 30 00:58 a.cpp

-rwxr-xr-x 1 pi pi    6492  7월 30 01:00 a.out

-rw-r--r-- 1 pi pi      37  7월 30 00:58 stdafx.h

-rw-r--r-- 1 pi pi 4324036  7월 30 01:01 stdafx.h.gch  


-c는 찾는거 포기 -_-

-x language

Specify explicitly the language for the following input files (rather than letting the compiler choose a default based on the file name suffix). This option applies to all following input files until the next -x option. Possible values for language are:

c  c-header  c-cpp-output

c++  c++-header  c++-cpp-output

objective-c  objective-c-header  objective-c-cpp-output

objective-c++ objective-c++-header objective-c++-cpp-output

assembler  assembler-with-cpp

ada

f77  f77-cpp-input f95  f95-cpp-input

java


-o file

Place output in file file. This applies regardless to whatever sort of output is being produced, whether it be an executable file, an object file, an assembler file or preprocessed C code.

If -o is not specified, the default is to put an executable file in a.out, the object file for source.suffix in source.o, its assembler file in source.s, a precompiled header file in source.suffix.gch, and all preprocessed C source on standard output.

[링크 : http://linux.die.net/man/1/gcc] 


췟 이건 안되네 -_-

pi@raspberrypi ~/src/pch $ gcc stdafx.h -o stdafx.h.gch

stdafx.h:1:18: fatal error: string: 그런 파일이나 디렉터리가 없습니다

compilation terminated. 



결론 -c -o .gch로 하자


2015/07/29 - [프로그램 사용/gcc] - gcc에서 precompiled header 사용하기




'프로그램 사용 > gcc' 카테고리의 다른 글

gcc -M -MM  (0) 2015.12.17
gcc 초기화 관련  (0) 2015.10.21
gcc에서 precompiled header 사용하기  (0) 2015.07.29
gcc 64bit 변수 선언하기  (0) 2015.07.14
gcc 32bit/ 64bit 컴파일하기  (0) 2015.07.14
Posted by 구차니