__fl_attr() for class methods

7 views
Skip to first unread message

Greg Ercolano

unread,
Jan 25, 2023, 10:37:30 PM1/25/23
to fltkc...@googlegroups.com

Is there a way to use __fl_attr() for class methods like Fl_Text_Buffer::printf() and Fl_Text_Buffer::vprintf()?

I assumed something like this would work, but it fails with weird errors:

 #include "Fl_Export.H"
+#include "fl_attr.h"
 
 class Fl_Text_Undo_Action;
 
@@ -289,8 +290,8 @@ public:
    */
   void append(const char* t) { insert(length(), t); }
 
-  void vprintf(const char *fmt, va_list ap);
-  void printf(const char* fmt, ...);
+  void vprintf(const char *fmt, va_list ap) __fl_attr((__format__(__printf__, 1, 0)));
+  void printf(const char* fmt, ...)         __fl_attr((__format__(__printf__, 1, 2)));
 

This seems like the same usage in fl_ask.h, it's just a method here
instead of a function.

Is there maybe some special syntax needed since these are methods in a class?
The GNU documentation seems unclear on this, and the error messages are as well:

/usr/local/src/fltk-1.4.x.git/FL/fl_attr.h:53:40: error: 'format' attribute argument 2 value '1' refers to parameter type 'Fl_Text_Buffer*'
   53 | #  define __fl_attr(x) __attribute__ (x)
      |                                        ^
/usr/local/src/fltk-1.4.x.git/FL/Fl_Text_Buffer.H:293:45: note: in expansion of macro '__fl_attr'
  293 |   void vprintf(const char *fmt, va_list ap) __fl_attr((__format__(__printf__, 1, 0)));
      |                                             ^~~~~~~~~
/usr/local/src/fltk-1.4.x.git/FL/fl_attr.h:53:40: error: 'format' attribute argument 2 value '1' refers to parameter type 'Fl_Text_Buffer*'
   53 | #  define __fl_attr(x) __attribute__ (x)
      |                                        ^
/usr/local/src/fltk-1.4.x.git/FL/Fl_Text_Buffer.H:294:45: note: in expansion of macro '__fl_attr'
  294 |   void printf(const char* fmt, ...)         __fl_attr((__format__(__printf__, 1, 2)));
      |                                             ^~~~~~~~~

I'm sure that "refers to parameter type 'Fl_Text_Buffer*' should be giving me a hint
but I'm not sure what to make of it.

I have a vague memory that non-static class methods might secretly have 'this' somehow
involved as the first argument (perhaps similar to python?), and perhaps with this low level
compiler stuff, __attribute__ and __format__() need to know about this offset for the two
argument index numbers?

I ask because I figure I might need this for the new Fl_Terminal widget I'm working on.

melcher....@googlemail.com

unread,
Jan 26, 2023, 3:22:14 AM1/26/23
to fltkc...@googlegroups.com
Yes. Just increment the two index values for the format string and for the start of the vararg list by one to accommodate for the „this“ pointer.

Sent from my iPhone

On 26. Jan 2023, at 04:37, Greg Ercolano <er...@seriss.com> wrote:


--
You received this message because you are subscribed to the Google Groups "fltk.coredev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkcoredev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkcoredev/85a78e20-7748-f6a3-8f01-532510dfde4a%40seriss.com.

melcher....@googlemail.com

unread,
Jan 26, 2023, 3:23:41 AM1/26/23
to fltk.coredev
class Fd_Project_Writer {
    void write_string(const char *,...) __fl_attr((__format__ (__printf__, 2, 3)));
};
Reply all
Reply to author
Forward
0 new messages