Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
March 04, 2011 Wrapping C that uses compiler extensions | ||||
---|---|---|---|---|
| ||||
This code confuses me... It's from the c mysql windows dll, libmysql.dll. size_t (*snprintf)(struct charset_info_st *, char *to, size_t n, const char *fmt, ...) ATTRIBUTE_FORMAT_FPTR(printf, 4, 5); #ifndef _my_attribute_h #define _my_attribute_h /* Disable __attribute__() on gcc < 2.7, g++ < 3.4, and non-gcc compilers. Some forms of __attribute__ are actually supported in earlier versions of g++, but we just disable them all because we only use them to generate compilation warnings. */ #ifndef __attribute__ # if !defined(__GNUC__) # define __attribute__(A) # elif GCC_VERSION < 2008 # define __attribute__(A) # elif defined(__cplusplus) && GCC_VERSION < 3004 # define __attribute__(A) # endif #endif /* __attribute__((format(...))) is only supported in gcc >= 2.8 and g++ >= 3.4 But that's already covered by the __attribute__ tests above, so this is just a convenience macro. */ #ifndef ATTRIBUTE_FORMAT # define ATTRIBUTE_FORMAT(style, m, n) __attribute__((format(style, m, n))) #endif /* __attribute__((format(...))) on a function pointer is not supported until gcc 3.1 */ #ifndef ATTRIBUTE_FORMAT_FPTR # if (GCC_VERSION >= 3001) # define ATTRIBUTE_FORMAT_FPTR(style, m, n) ATTRIBUTE_FORMAT(style, m, n) # else # define ATTRIBUTE_FORMAT_FPTR(style, m, n) # endif /* GNUC >= 3.1 */ #endif #endif |
March 04, 2011 Re: Wrapping C that uses compiler extensions | ||||
---|---|---|---|---|
| ||||
Posted in reply to simendsjo Attachments:
| simendsjo wrote: > > This code confuses me... It's from the c mysql windows dll, libmysql.dll. > > size_t (*snprintf)(struct charset_info_st *, char *to, size_t n, > const char *fmt, > ...) ATTRIBUTE_FORMAT_FPTR(printf, 4, 5); > You can safely ignore the “ATTRIBUTE_FORMAT_FPTR(printf, 4, 5)”. All it does is that it enables the compiler to check the format string against the variable arguments and generate a warning if they do not match. Jerome -- mailto:jeberger@free.fr http://jeberger.free.fr Jabber: jeberger@jabber.fr |
March 04, 2011 Re: Wrapping C that uses compiler extensions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jérôme M. Berger | On 04.03.2011 22:42, "Jérôme M. Berger" wrote: > int main(string[] args) { > auto s1 =(); // MH MH > auto s2 =(); // OK > s2.c =ull; // OK > return 0; > } Is part of your message gone? > You can safely ignore the “ATTRIBUTE_FORMAT_FPTR(printf, 4, 5)”. That I understood :) Thanks! |
March 05, 2011 Re: Wrapping C that uses compiler extensions | ||||
---|---|---|---|---|
| ||||
Posted in reply to simendsjo Attachments:
| simendsjo wrote: > On 04.03.2011 22:42, "Jérôme M. Berger" wrote: >> int main(string[] args) { >> auto s1 =(); // MH MH >> auto s2 =(); // OK >> s2.c =ull; // OK >> return 0; >> } > > Is part of your message gone? > Uh, I did not write that. >> You can safely ignore the “ATTRIBUTE_FORMAT_FPTR(printf, 4, 5)”. > > That I understood :) Thanks! Then if the issue is with the rest of the definition, it is more or less equivalent to (you will need to translate the argument declaration too): alias size_t function (struct charset_info_st *, char *to, size_t n, const char *fmt, ...) snprintf; Jerome -- mailto:jeberger@free.fr http://jeberger.free.fr Jabber: jeberger@jabber.fr |
March 05, 2011 Re: Wrapping C that uses compiler extensions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jérôme M. Berger | On 05.03.2011 08:58, "Jérôme M. Berger" wrote: > simendsjo wrote: >> On 04.03.2011 22:42, "Jérôme M. Berger" wrote: >>> int main(string[] args) { >>> auto s1 =(); // MH MH >>> auto s2 =(); // OK >>> s2.c =ull; // OK >>> return 0; >>> } >> >> Is part of your message gone? >> > Uh, I did not write that. Checked the web newsinterface, and I see your post. In thunderbird I got another post from Tom with the subject "Struct reference returning function and const members" in your post... >>> You can safely ignore the “ATTRIBUTE_FORMAT_FPTR(printf, 4, 5)”. >> >> That I understood :) Thanks! > > Then if the issue is with the rest of the definition, it is more or > less equivalent to (you will need to translate the argument > declaration too): > > alias size_t function (struct charset_info_st *, char *to, size_t n, > const char *fmt, > ...) snprintf; > > Jerome The definition is inside a struct. I shouldn't use an alias then..? This is the C struct: typedef struct my_charset_handler_st { // snip size_t (*snprintf)(struct charset_info_st *, char *to, size_t n, const char *fmt, ...) ATTRIBUTE_FORMAT_FPTR(printf, 4, 5); // snip } And this is my D struct: struct my_charset_handler_st { // snip size_t function(charset_info_st*, char* to, size_t n, const char* fmt, ...) snprintf; // snip } |
March 05, 2011 Re: Wrapping C that uses compiler extensions | ||||
---|---|---|---|---|
| ||||
Posted in reply to simendsjo Attachments:
| simendsjo wrote: > On 05.03.2011 08:58, "Jérôme M. Berger" wrote: >> simendsjo wrote: >>> On 04.03.2011 22:42, "Jérôme M. Berger" wrote: >>>> int main(string[] args) { >>>> auto s1 =(); // MH MH >>>> auto s2 =(); // OK >>>> s2.c =ull; // OK >>>> return 0; >>>> } >>> >>> Is part of your message gone? >>> >> Uh, I did not write that. > > Checked the web newsinterface, and I see your post. In thunderbird I got another post from Tom with the subject "Struct reference returning function and const members" in your post... > >>>> You can safely ignore the “ATTRIBUTE_FORMAT_FPTR(printf, 4, 5)”. >>> >>> That I understood :) Thanks! >> >> Then if the issue is with the rest of the definition, it is more or >> less equivalent to (you will need to translate the argument >> declaration too): >> >> alias size_t function (struct charset_info_st *, char *to, size_t n, >> const char *fmt, >> ...) snprintf; >> >> Jerome > > The definition is inside a struct. I shouldn't use an alias then..? > No, you are right, I thought there was a typedef in the C code... > This is the C struct: > typedef struct my_charset_handler_st > { > // snip > size_t (*snprintf)(struct charset_info_st *, char *to, size_t n, > const char *fmt, > ...) ATTRIBUTE_FORMAT_FPTR(printf, 4, 5); > // snip > } > > And this is my D struct: > struct my_charset_handler_st > { > // snip > size_t function(charset_info_st*, char* to, size_t n, > const char* fmt, > ...) snprintf; > // snip > } Yes, that should be about right. Jerome -- mailto:jeberger@free.fr http://jeberger.free.fr Jabber: jeberger@jabber.fr |
Copyright © 1999-2021 by the D Language Foundation