¿Por qué llamar a macro de esta manera?

I read larbin source code recently. But I have a doubt. I the global.h file define the global class, at the end of this file have a macro like this:

#define setPoll(fds, event) \
global::pollfds[global::posPoll].fd = fds; \
global::pollfds[global::posPoll].events = event; \

But in the fetch/fetchPipe.cc file, call this macro like this:

global::setPoll(n, POLLOUT);

The question is why use global:: to call this macro? I think use

setPoll(n, POLLOUT);

is ok. Any body can tell me why?

preguntado el 30 de julio de 12 a las 13:07

global::setPoll looks like a bug to me. It would expand to global::global::pollfds[... -

@eharvest C++, C doesn't accept global::whatever. -

@eharvest: Technically C++, since there's apparently a class, but spiritually C since it uses macros instead of inline methods. -

1 Respuestas

The source code is a complete mess, it won't even compile. It seems that global.h has been changed between version 2.2.2 and the current version 2.6.3 without addressing those changes in fetch/fetchPipe.h. Also have a look at those include statements in global.cc:

#include <iostream.h> // iostream.h?
#include <unistd.h>   // twice, see below
#include <errno.h>
#include <string.h>   // mixing C++ and C libraries
#include <sys/types.h>
#include <unistd.h>

This code is outdated and not standard C++. There are several other things wrong. But back to your question: yes, setPoll(n, POLLOUT); should be sufficient. Using global::setPoll will not result in a bug, since this will expand to

global::global::pollfds[global::posPoll].fd = fds;
global::pollfds[global::posPoll].events = event;

y global es un struct (consulte la sección del Mike Seymour's comment).

contestado el 23 de mayo de 17 a las 13:05

You are right, it's not standard c++. I surprise is that it can compile ok with global::setPoll(n, POLLOUT) at gcc version 4.5.2 (Ubuntu/Linaro 4.5.2-8ubuntu4) - laifjei

global::global::pollfds is not an error if global is a class; a class-name is injected into the class's scope, so global, global::global y global::global::global::global::global son todos equivalentes. - mike seymour

@MikeSeymour: Accidentally misread the declaration of global and thought it was a namespace. My fault. - Zed

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.