2

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; \
global::posPoll++

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?

3
  • 4
    global::setPoll looks like a bug to me. It would expand to global::global::pollfds[...
    – ugoren
    Jul 30, 2012 at 12:48
  • 2
    @eharvest C++, C doesn't accept global::whatever. Jul 30, 2012 at 12:55
  • @eharvest: Technically C++, since there's apparently a class, but spiritually C since it uses macros instead of inline methods.
    – MSalters
    Jul 30, 2012 at 12:56

1 Answer 1

1

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;
global::posPoll++;

and global is a struct (see Mike Seymour's comment).

3
  • 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
    Jul 30, 2012 at 13:20
  • 1
    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 and global::global::global::global::global are all equivalent. Jul 30, 2012 at 13:27
  • @MikeSeymour: Accidentally misread the declaration of global and thought it was a namespace. My fault.
    – Zeta
    Jul 30, 2012 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.