Giter Club home page Giter Club logo

c's Introduction

C Stuff

Special Macros

__LINE__ __COUNTER__

    printf("__LINE__ Macro %d\n", __LINE__);
    printf("__COUNTER__ Macro %d\n", __COUNTER__);
    printf("__COUNTER__ Macro %d\n", __COUNTER__);
    printf("__COUNTER__ Macro %d\n", __COUNTER__)

Gives

__LINE__ Macro 45
__COUNTER__ Macro 0
__COUNTER__ Macro 1
__COUNTER__ Macro 2

Variadic Macros

Stringize the macro input argument with #, this adds quotes to the input argument.

#define stringize(x) #x
 stringize(fff)

Produces:

 "fff"

Concatenate Macro

Change the entry point of an application:

When, for some reason, the entry point function has to be renamed, the linker is responsible to assign the entry point. For example:

#include <stdio.h>

int entry()
{
  return 0;
}

And the compile/link command is now:

gcc -o entry.exe entry.c -Wl, -eentry -nostartfiles

The -Wl,-eentry passes arguments to the linker, and the linker takes a -e argument to set the entry function.

The command -nostrartfiles omits the ctr*.o files containing _start but stills allows to use a libc.

Another way to acomplish this is to use the binutils, this provides the command objcopy to make an arbitrary function the new entry point.

This requires a relocatable compilation, which is done with the gcc flag -c

This way:

gcc -c program.c -o program.exe

Then redefine the the entry to be main:

objcopy --redefine-sym entry=main program.o

Now use gcc to compile the new object file:

gcc program.o -o program

If the program already has a function called main, performa a separated objcopy invocation:

objcopy --redefine-sym oldmain=main program.o

c's People

Contributors

yhoazk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.