On Wednesday 17 August 2011 16:28:42 Gisle Vanem wrote: > "Alon Bar-Lev" <alon.bar...@gmail.com> wrote: > > These macros are soooooooo ugly! > > I tend to agree; had to read the code closely.
I tend to disagree. =) Using macros here makes the code more readable. And managable. Imaging if there'll be another 20 functions to wrap. The result without macros would be a plain mess. I agree however that this whole construct is weird, but I guess that's what you get when you used unsupported APIs. The way the library is loaded in cryptoapi.c opens a dll hijacking security hole, btw. See http://www.microsoft.com/technet/security/advisory/2269637.mspx and now imagine this being done in many different places many different ways. I know some people are generally allergic to macros, but reconsider for this situation please. Besides that if the hack in cryptoapi.c would have been done right it would not pose a threat anymore as MinGW knows CryptAcquireCertificatePrivateKey by now. I'll post a patch that removes that hunk later. > But this hack was cool: > > union { > FUNC ## _fn *type; > FARPROC *ptr; > } u = { .type = &(LIB ## _ ## FUNC) }; > ... > *(u.ptr) = GetProcAddress (lib, (#FUNC)); > > Where did you get that Heiko? From http://cellperformance.beyond3d.com/articles/2006/06/understanding- strict-aliasing.html. If you're less artistic gcc warns about strict aliasing being violated (with the right error level at least). Heiko -- Heiko Hund | Software Engineer | Phone +49-721-25516-237 | Fax -200 Astaro a Sophos Company | Amalienbadstr. 41 Bau 52 | 76227 Karlsruhe | Germany Commercial Register: Mannheim HRA 702710 | Headquarter Location: Karlsruhe Represented by the General Partner Astaro Verwaltungs GmbH Amalienbadstraße 41 Bau 52 | 76227 Karlsruhe | Germany Commercial Register: Mannheim HRB 708248 | Executive Board: Gert Hansen, Markus Hennig, Jan Hichert, Günter Junk, Dr. Frank Nellissen