|
I came across these 2 macros in Linux kernel code. I know they are instructions to compiler (gcc) for optimizations in case of branching. My question is, can we use these macros in user space code? Will it give any optimization? Any example will be very...
Started by vinit dhatrak on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
The likely() and unlikely() macros are pretty names defined in the kernel headers for something) __builtin_expect((x),1) #define unlikely(x) __builtin_expect((x),0)
The __builtinexpect macros are GCC specific macros that use....
|
|
Hi,
I was reading some code written in C this evening, and at the top of the file was the function-like macro HASH:
#define HASH(fp) (((unsigned long)fp)%NHASH)
This left me wondering, why would somebody choose to implement a function this way using a...
Started by Ralph on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Some problems I ....
But in your example, the macro turns into 1-2 machine language instructions of.
It might not seem like much.
Introduces call-stack setup and restore Macros like that avoid the overhead of a function call.
|
|
Hi, I don't know how to call a macro inside another macro avoiding the ring bell stop of the inner macro, because that stops the external macro. In particular, I have to make two searches , and I've defined one in one macro and the other have to search...
Started by salva on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
The macro system is great, but it is limited in power, and it sounds like you are trying to do bet is to write the inner loop in Lisp and run the outer loop as a macro (or write it in Lisp as well searches in a macro easily....
|
Ask your Facebook Friends
|
Hello,
gcc 4.4.2 c89
I have this code snippet that I have to repeat in a lot of my code. I am just wondering is there a way to make it short by using a macro function?
There is the code I would like to change.
ERR_INFO error_info; /* create error object...
Started by robUK on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Used often enough, you might be still be better off with a real functionAre you trying... .
DISPLAY(message) // Pass an argument to macro
You need to make it work like a function call, so it can having the function-like macro.
|
|
I've been digging through some parts of the Linux kernel, and found calls like this:
if (unlikely(fd < 0)) { /* Do something */ }
or
if (likely(!err)) { /* Do something */ }
I've found the definition of them:
#define likely(x) __builtin_expect((x),...
Started by terminus on
, 9 posts
by 8 people.
Answer Snippets (Read the full thread at stackoverflow):
These are macros that give hints to the compiler about which way a branch may go.
Like all such performance for platforms that do not support static branch hints.
Is correct most of the time, this will tend to be good for performance .
|
|
Dear friends,
Im starting this poll to see how important users of Total Commander find the idea of macros for their favourite file manager.
For those who dont really know what macros are well, in very general terms, its a series of collections of conditions...
Started by pdavit on
, 15 posts
by 5 people.
Answer Snippets (Read the full thread at ghisler):
The poll is about classical "record / play" macro (like me)
For example this tool would help Christian implementing such a thing: http://www.ekassw.com to specific subjects).
What type of "macro" user would like to have.
|
|
I'd like to get the C preprocessor to generate macros for me (i.e., I'm using C99 only). I'd write a macro
#define make_macro(in) <...magic here...>
and when I put
make_macro(name1) make_macro(name2)
later in the code, it would expand to
#define...
Started by afluff on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Use like this:
make_macro(name1) make_macro(name2,1)
and this would generate
name1_fn you could not use other macros in your macro but you could not do
#define TEST #define HALLO 33 int with my default compiler....
|
|
Does anyone know how to properly save/reuse macros recorded inside of a vim editor?
Started by jnadro52 on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
The format is something like:
let @q = 'macro contents the following line to your ~/.vimrc....
Write your macros inside your ~/.vimrc, to define a macro launched by CTRL+O by example, add will be around the next time you start vim.
|
|
In a previous question what I thought was a good answer was voted down for the suggested use of macros
#define radian2degree(a) (a * 57.295779513082) #define degree2radian(a) (a * 0.017453292519)
instead of inline functions. Please excuse the newbie question...
Started by semaj on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
For this specific macro, if I use a few examples for....
Defines can be redfined undefined, and there is no type checking .
macros are evil because they look like functions so they trick you into using them just like functions.
|
|
What is the worst real-world macros/pre-processor abuse you've ever come across (please no contrived IOCCC answers *haha*)?
Please add a short snippet or story if it is really entertaining. The goal is to teach something instead of always telling people...
Started by Trevor Boyd Smith on
, 59 posts
by 54 people.
Answer Snippets (Read the full thread at stackoverflow):
MrValdez is annoyed by the GetObject macro found(-1); \ } \
I was pretty....
Windows.h has a lot of functions that abused macros.
At the time it seemed like a good idea to "pass" a macro.
macros, but it was just too much.
|