digitalmars.D.learn - Wrapping C that uses compiler extensions
- simendsjo (41/42) Mar 04 2011 This code confuses me... It's from the c mysql windows dll, libmysql.dll...
- =?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= (12/19) Mar 04 2011 You can safely ignore the =E2=80=9CATTRIBUTE_FORMAT_FPTR(printf, 4, 5)=...
- simendsjo (3/10) Mar 04 2011 That I understood :) Thanks!
- =?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= (14/27) Mar 04 2011 =E2=80=9D.
- simendsjo (23/45) Mar 05 2011 Checked the web newsinterface, and I see your post. In thunderbird I got...
- =?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= (11/64) Mar 05 2011 5)=E2=80=9D.
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__
#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
#endif
/*
__attribute__((format(...))) on a function pointer is not supported
until gcc 3.1
*/
#ifndef ATTRIBUTE_FORMAT_FPTR
#endif
#endif
Mar 04 2011
simendsjo wrote:=20 This code confuses me... It's from the c mysql windows dll, libmysql.dl=l.=20 size_t (*snprintf)(struct charset_info_st *, char *to, size_t n, const char *fmt, ...) ATTRIBUTE_FORMAT_FPTR(printf, 4, 5); =20You can safely ignore the =E2=80=9CATTRIBUTE_FORMAT_FPTR(printf, 4, 5)=E2= =80=9D. 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 --=20 mailto:jeberger free.fr http://jeberger.free.fr Jabber: jeberger jabber.fr
Mar 04 2011
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!
Mar 04 2011
simendsjo wrote:On 04.03.2011 22:42, "J=C3=A9r=C3=B4me M. Berger" wrote:Uh, I did not write that.int main(string[] args) { auto s1 =3D(); // MH MH auto s2 =3D(); // OK s2.c =3Dull; // OK return 0; }=20 Is part of your message gone? =20=E2=80=9D.You can safely ignore the =E2=80=9CATTRIBUTE_FORMAT_FPTR(printf, 4, 5)==20 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 --=20 mailto:jeberger free.fr http://jeberger.free.fr Jabber: jeberger jabber.fr
Mar 04 2011
On 05.03.2011 08:58, "Jérôme M. Berger" wrote:simendsjo wrote: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...On 04.03.2011 22:42, "Jérôme M. Berger" wrote:Uh, I did not write that.int main(string[] args) { auto s1 =(); // MH MH auto s2 =(); // OK s2.c =ull; // OK return 0; }Is part of your message gone?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 }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; JeromeYou can safely ignore the “ATTRIBUTE_FORMAT_FPTR(printf, 4, 5)”.That I understood :) Thanks!
Mar 05 2011
simendsjo wrote:On 05.03.2011 08:58, "J=C3=A9r=C3=B4me M. Berger" wrote:tsimendsjo wrote:=20 Checked the web newsinterface, and I see your post. In thunderbird I go=On 04.03.2011 22:42, "J=C3=A9r=C3=B4me M. Berger" wrote:Uh, I did not write that.int main(string[] args) { auto s1 =3D(); // MH MH auto s2 =3D(); // OK s2.c =3Dull; // OK return 0; }Is part of your message gone?another post from Tom with the subject "Struct reference returning function and const members" in your post... =205)=E2=80=9D.You can safely ignore the =E2=80=9CATTRIBUTE_FORMAT_FPTR(printf, 4, =rThat I understood :) Thanks!Then if the issue is with the rest of the definition, it is more o=No, you are right, I thought there was a typedef in the C code...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=20 The definition is inside a struct. I shouldn't use an alias then..? =20This 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 } =20 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 --=20 mailto:jeberger free.fr http://jeberger.free.fr Jabber: jeberger jabber.fr
Mar 05 2011








=?UTF-8?B?IkrDqXLDtG1lIE0uIEJlcmdlciI=?= <jeberger free.fr>