[Programming Language]
C++
[Question]
Print "Hello World!" in the console without using a semicolonin your code.Code:;
OT: Bugoya sa fork bomb![]()
[Programming Language]
C using gcc compiler
[QUESTION]
How can you make this code print gvar as 666 without editing the main function?
Code:#include <stdio.h> void func(void); int gvar = 0; int main(void) { printf("In main. gvar=%d\n", gvar); return 1; } void func(void) { gvar = 666; }
Ladies and gentlemen, I present to you a solution that doesn't involve editing the file at all:
This works because the preprocesssor expands the code to:Code:simoncpu@simoncpu ~ $ gcc -D'gvar=gvar=666,x' saverok.c -o saverok simoncpu@simoncpu ~ $ ./saverok In main. gvar=666
Code:void func(void); int gvar=666,x = 0; int main(void) { printf("In main. gvar=%d\n", gvar=666,x); return 1; } void func(void) { gvar=666,x = 666; }
Last edited by Sarevok; 05-22-2014 at 10:26 AM.
nakit-an ra jud nako ang meaning. pangdebug diay
Code:-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.
Yepp, pwede ka maka-define ug macro using the command line. Bale, gi-himo nako nga macro ang "gvar" to redefine it to something else... I think ang Visual Studio pwede sad... hehe...
before ko magpost ug new question kay ako sa ipakita ang lain na answer sa ako previous question
Ichange ra nimo ang pagdeclare sa function into:
Code:void func(void) __attribute__ ((constructor));
mangita sa ko new tricks![]()
Similar Threads |
|