Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The use of __attribute__((__constructor__)) #58

Closed
Orvid opened this issue Aug 14, 2015 · 6 comments
Closed

The use of __attribute__((__constructor__)) #58

Orvid opened this issue Aug 14, 2015 · 6 comments

Comments

@Orvid
Copy link
Contributor

Orvid commented Aug 14, 2015

Is there a specific reason that __attribute__((__constructor__)) is used rather than a dynamic initializer like:

static struct Example {
Example() { /* Do some assembly construction logic here */ }
} s_example;

I ask because, although I can provide the same thing with MSVC, it's not exactly pretty, and it would be much cleaner to switch to initializers.

@bugok
Copy link
Contributor

bugok commented Aug 17, 2015

Thanks for reporting @Orvid.
Are you referring to a specific location? I see this happening in several places in the code.
For example: https://github.com/facebook/proxygen/blob/master/proxygen/lib/http/HTTPMethod.cpp#L27

In this example - I believe that it's to make sure that this structure is available when main() is called.

@Orvid
Copy link
Contributor Author

Orvid commented Aug 17, 2015

It's just a general question, regarding all uses of the attribute.

@afrind
Copy link
Contributor

afrind commented Sep 21, 2015

I think we're trying to move away from static initializers with non-trivial destructors because destruction order is difficult to reason about.

@russoue
Copy link
Contributor

russoue commented Feb 12, 2016

@Orvid, can we close this issue?

@russoue
Copy link
Contributor

russoue commented Feb 12, 2016

@Orvid, it seems that we have another issue opened for this: #66, can you please close this one?

@Orvid
Copy link
Contributor Author

Orvid commented Feb 12, 2016

Yep.

@Orvid Orvid closed this as completed Feb 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants