[C/C++] Small tip - Argument passed to main() function.

Language/C&C++ 2015.10.19 22:56

In general, main function is used as below.


int main(int argc, const char *argv[]) {

}


But, it can be expanded like below


int main(int argc, const char *argv[], const char **envp) {

        while (*envp) {

                printf("%s\n", *envp++);

        }

}


By this way, we can use environment variables easily.

=> This matches parameters of execle() and execvpe() at Linux.



신고

'Language > C&C++' 카테고리의 다른 글

[C/C++] Small tip - Argument passed to main() function.  (0) 2015.10.19
[C/C++] Template with value  (0) 2015.04.28
[C/C++] sizeof array  (0) 2015.03.19
[Macro] '##' macro operator  (0) 2015.02.11
'malloc' and 'Segmentation fault'  (0) 2014.07.25
[GCC] Initialize array...  (0) 2014.07.25
Trackback 0 : Comment 0

[gnumake] Tips and command line variable.

Tools 2015.10.19 22:52

GNUMake document says

"An argument that contains ‘=’ specifies the value of a variable: ‘v=x’ sets the value of the variable v to x. If you specify a value in this way, all ordinary assignments of the same variable in the makefile are ignored; we say they have been overridden by the command line argument"


This means, value defined as command-line argument has top priority in terms of variable definition.


< Make file >

PRIV_V=hello_OUT

$(info $(PRIV_V))


all: a b

@echo all


a: PRIV_V := hello_A

a:

@echo $(PRIV_V)


b: PRIV_V := hello_B

b:

@echo $(PRIV_V)




< Test >

$ export PRIV_V=ENV

$ make

hello_OUT

hello_A

hello_B

all


$ make PRIV_V=CMD

CMD

CMD

CMD

all


* Tips : Variable definition in gnumake command line.

Variable definition syntax in the Makefile, is also available as command line argument.

Example.

$ make CC=Hello

$ make CC:=Hello

$ make CC+=Hello

신고
Trackback 1 : Comment 0

[Python] binding function parameter default value.

Language/Python 2015.09.06 06:11

function 을 define하는 시점에 default value를 binding한다.

(Spec.을 찾아본건 아니고.. 시험적으로...)



[test.py]


_DEFVAL = 10


def set_def(val):

    global _DEFVAL

    _DEFVAL = val


def prdef(val=_DEFVAL):

    print '+++ ' + str(val) + '\n'


prdef()

set_def(0)

prdef()


============== outputs ==============

+++ 10


+++ 10


신고

'Language > Python' 카테고리의 다른 글

[Python] binding function parameter default value.  (0) 2015.09.06
Trackback 0 : Comment 0
◀ PREV : [1] : [2] : [3] : [4] : [5] : [6] : [7] : [8] : [9] : ... [100] : NEXT ▶

티스토리 툴바