/git/fltk/master/test/handle_keys.cxx:337:43: error: macro "putchar" passed 3 arguments, but takes just 1 337 | win->tty->Fl_Terminal::putchar('a', 0, 2); | ^ /path/to/fltk/test/handle_keys.cxx:29: note: macro "putchar" defined here 29 | #define putchar(c) putc(c, stdout) | /path/to/fltk/test/handle_keys.cxx: In function ‘int main(int, char**)’: /path/to/fltk/test/handle_keys.cxx:337:26: error: statement cannot resolve address of overloaded function 337 | win->tty->Fl_Terminal::putchar('a', 0, 2); | ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~ ninja: build stopped: subcommand failed. Conclusion:Since we can't prevent that a system defines putchar as a macro we should IMHO rename the function rather than trying to work around it by patching the FLTK source file. And of course we can't '#undef putchar' anywhere in a public header file. Telling users that run into this issue to '#undef putchar' wouldn't be a good suggestion as well.
Hi all,
TL;DR: I believe we should rename Fl_Terminal::putchar() to something that doesn't conflict with the global function name putchar() which *may* be defined as a macro.
Yuck.
We could rename it to putc() which, if POSIX says needs to be implemented
as a function (and not a macro), should be allowed. But, that still might cause
problems with the #define putchar() macro calling the wrong thing, for instance,
in a derived class where prefixes that would bypass the macro (like "->" and ".")
aren't needed.
There's a reason the method is implemented as putchar(), to emulate the
putchar() function within the widget. This should be legal to do, especially
as a class method.
And if calling it putc() would suffer similar interference with the putchar()
macro, then we couldn't use putc() either, which is just bad.
For this reason I'm not sure we should have to chase arguably broken platforms
like this. (If POSIX said "must be a macro" then I'd change my mind.)
I'd instead leave it to the application programmer to solve, like any other
messy platform specific issue, by adding "#undef putchar" before
"#include <FL/Fl_Terminal.H>" and similarly handle their use of putchar()
to non-fltk modules.
My feeling is take a stand and push the problem resolution back upstream
to its source, perhaps documenting the issue and how to workaround, assuming
the workaround is "workable".
On 3/25/24 12:21, 'Albrecht Schlosser' via fltk.coredev wrote:
Hi all,
TL;DR: I believe we should rename Fl_Terminal::putchar() to something that doesn't conflict with the global function name putchar() which *may* be defined as a macro.
We could rename it to putc() which, if POSIX says needs to be implemented
as a function (and not a macro), should be allowed. But, that still might cause
problems with the #define putchar() macro calling the wrong thing, for instance,
in a derived class where prefixes that would bypass the macro (like "->" and ".")
aren't needed.
There's a reason the method is implemented as putchar(), to emulate the
putchar() function within the widget. This should be legal to do, especially
as a class method.
And if calling it putc() would suffer similar interference with the putchar()
macro, then we couldn't use putc() either, which is just bad.
For this reason I'm not sure we should have to chase arguably broken platforms
like this. (If POSIX said "must be a macro" then I'd change my mind.)
I'd instead leave it to the application programmer to solve, like any other
messy platform specific issue, by adding "#undef putchar" before
"#include <FL/Fl_Terminal.H>" and similarly handle their use of putchar()
to non-fltk modules.
My feeling is take a stand and push the problem resolution back upstream
to its source, perhaps documenting the issue and how to workaround, assuming
the workaround is "workable".
   TL;DR: If it's truly not possible to work around, then I
suppose it has to change.
   Perhaps putchar_utf8(),
   And if POSIX explicitly allows it, well then I suppose we have
to live
   with POSIX and all the warts it implies.
   But had 1.4.0 released with putchar() in place, I'd think
there'd be
   possible workarounds.
On 3/25/24 14:00, 'Albrecht Schlosser' via fltk.coredev wrote:
What would be wrong with renaming the Fl_Terminal::putcha() method to avoid name clashes in the first place?
I m following this with a certain awe. Defining a macro has tons of side effects, and defining such simple word as `putchar` in a system header is horrible.
Anyway, we can fight macros with macros... .
Not sure it that would compile, or work in this context, but if we define our own macro, we should be able to generate the same code, even if putchar is a macro. I would add `putc` as a method, so even if there is #define putchar(x) putc(x, stdout) somewhere, we would still compile correctly:
#define putchar(x) putc(x, stdout)
class Fl_Terminal { int putc(int c, FILE *); // 2nd arg is ignored#ifdef putchar #define FL_TERMINAL_PUTCHAR putchar int FL_TERMINAL_PUTCHAR(int c); #undef FL_TERMINAL_PUTCHAR#else int putchar(int c);#endif
}
so calling myTerminal->putchar('a'); should do the right thing in either case, and Fl_Terminal::putchar() should exist, even if putchar is a macro.
There are other Unix systems that seems to intentionally provide amacro for putchar() and document it. IBM documentation for AIX: <https://www.ibm.com/docs/en/aix/7.2?topic=p-putc-putchar-fputc-putw-subroutine> | | The putchar macro is the same as the putc macro except that | putchar writes to the standard output. Oracle documentation for Solaris: <https://docs.oracle.com/cd/E88353_01/html/E37843/putchar-3c.html> | | The call putchar(c) is equivalent to putc(c, stdout). | The putchar() routine is implemented as a macro.
--
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/d89390e4-6985-456a-8321-a656bf0dc74d%40aljus.de.
put() or put_char() works for me --
shorter is better IMHO.
#define putchar(a) putc(a, stdout)
#define empty()
#define delay(f) f empty()
// The function name will actually be `putchar`!
int delay(putchar) (int x) {
 return x;
}
//#undef putchar
int main(int argc, char **argv) {
 putchar('2');
}On 4/2/24 05:14, 'Albrecht Schlosser' via fltk.coredev wrote:
On 4/2/24 05:31 Greg Ercolano wrote:
put() or put_char() works for me -- shorter is better IMHO.
I like put() as well, that's IMHO a good choice. Let's go with put().
Greg, would you like to update the code, or would you like me to do it?
On 4/2/24 05:14, 'Albrecht Schlosser' via fltk.coredev wrote:
On 4/2/24 05:31 Greg Ercolano wrote:
put() or put_char() works for me -- shorter is better IMHO.
I like put() as well, that's IMHO a good choice. Let's go with put().
Greg, would you like to update the code, or would you like me to do it?
Looking into the code, there's an existing method "print_char()" with a few variations:
 void putchar(const char *text, int len, int drow, int dcol);
 void putchar(char c, int drow, int dcol);
 void print_char(const char *text, int len=-1);
 void print_char(char c);
The print_char() methods:
   advance the cursor
   handles control codes like \n, \t, \r, etc.
   handles ANSI esc sequences
   Must be a single character (ascii or utf8)
The putchar() methods:
   Doesn't move the cursor
   Don't handle ANSI escape sequences
   Don't handle control chars
   Must be a single character (ascii or utf8)
"char" seems important to keep in the name, so as not to be confused with
methods that handle multichar strings (like printf() and append()).
So I think put() shouldn't be used for that reason.
Since putchar() also doesn't move the cursor, perhaps a better name is plot_char(),
since it's more like plotting pixels than "printing".
Given all that, I'm thinking plot_char() or plotchar().
On 4/2/24 08:51, 'Albrecht Schlosser' via fltk.coredev wrote:
Since putchar() also doesn't move the cursor, perhaps a better name is plot_char(),
since it's more like plotting pixels than "printing".
But a plotter would also move its pen ("cursor"), wouldn't it? ;-)
--
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/761f17f3-67de-42aa-b16a-a9d32ea6ccdb%40aljus.de.
Holding for a reply from Albrecht, as he's the one that didn't
like the 'plot' idea.
I do think plot is the better choice given the x,y args and the
"does not affect the
cursor position" behavior. (Confusion about pen plotter behavior
seems like a stretch)
I also give weight to Bill's opinion because he gifted us FLTK.
But I'm open to whatever you guys (or anyone else) can agree on,
and will
implement that.
--
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/6b58a150-4a78-4618-8e95-dbdde2caadf1%40seriss.com.
No problem here, I'd be fine with plot_char(), if that's preferred by you and others.