Warning issue
In my program, I use an amalgamation.c file with all needed PDCurses-Mod files needed to support WinCon.
I think such an amalgamation.c makes it easier to build; no need for a pdcurses.lib.
And amalgamation.c:
#define PDC_99 1
#define PDC_WIDE
#define PDC_FORCE_UTF8
#include "addch.c"
#include "addstr.c"
#include "attr.c"
#include "border.c"
#include "bkgd.c"
#include "clear.c"
#include "color.c"
#include "getch.c"
#include "getyx.c"
#include "initscr.c"
#include "inopts.c"
#include "kernel.c"
#include "mouse2.c"
#include "move.c"
#include "outopts.c"
#include "overlay.c"
#include "pad.c"
#include "pdcdisp.c"
#include "pdcgetsc.c"
#include "pdckbd.c"
#include "pdcscrn.c"
#include "pdcsetsc.c"
#include "pdcutil.c"
#include "panel.c"
#include "printw.c"
#include "refresh.c"
#include "scroll.c"
#include "slk.c"
#include "termattr.c"
#include "touch.c"
#include "util.c"
#include "winclip.c"
#include "window.c"
#include "debug.c"
#pragma comment (lib, "winmm.lib")
But I get several warning like:
f:\gv\WinKit\Include\10.0.26100.0\um\winnls.h(1556): warning C4005: 'IS_HIGH_SURROGATE': macro redefinition
addch.c(487): note: see previous definition of 'IS_HIGH_SURROGATE'
f:\gv\WinKit\Include\10.0.26100.0\um\winnls.h(1557): warning C4005: 'IS_LOW_SURROGATE': macro redefinition
addch.c(486): note: see previous definition of 'IS_LOW_SURROGATE'
f:\gv\WinKit\Include\10.0.26100.0\um\wincontypes.h(103): warning C4005: 'MOUSE_MOVED': macro redefinition
curses.h(264): note: see previous definition of 'MOUSE_MOVED'
pdckbd.c(657): warning C4459: declaration of 'event_count' hides global declaration
pdckbd.c(11): note: see declaration of 'event_count'
util.c(201): warning C4005: 'IS_HIGH_SURROGATE': macro redefinition
f:\gv\WinKit\Include\10.0.26100.0\um\winnls.h(1556): note: see previous definition of 'IS_HIGH_SURROGATE'
util.c(202): warning C4005: 'IS_LOW_SURROGATE': macro redefinition
f:\gv\WinKit\Include\10.0.26100.0\um\winnls.h(1557): note: see previous definition of 'IS_LOW_SURROGATE'
I'm especially concerned about IS_HIGH_SURROGATE and IS_LOW_SURROGATE.
Some of the redefinitions differs from my WinNls.h.
Can this be fixed?
Edit:
adding a #include <windows.h> at the top is a bit better.
But these warnings smells like a bug:
pdckbd.c(657): warning C4459: declaration of 'event_count' hides global declaration
pdckbd.c(11): note: see declaration of 'event_count'
Should it be:
--- a/wincon/pdckbd.c 2025-07-14 09:52:27
+++ b/wincon/pdckbd.c 2025-07-15 09:39:31
@@ -654,7 +654,7 @@
incomplete_event = _add_raw_mouse_event( button, event, modifiers, x, y);
while( incomplete_event)
{
- DWORD event_count = 0;
+ event_count = 0;
int remaining_ms = SP->mouse_wait;
while( !event_count && remaining_ms)
Hmmm... this is (to put it very mildly) an extremely unusual way of doing things. Actually, not one I've ever heard of before.
Almost any library built in this manner will break. Most will break much more thoroughly than what you're seeing here. Each library so built will present some batch of odd problems, and will result in an unsupported configuration that will almost never work without further tweaking. Ask for help for a library so compiled, and the first reply will always be "why aren't you building the library normally?". (Which, actually, was my immediate reaction. And I'm still wondering why?)
That said, a couple of fixes came out of this exercise :
- The
IS_*_SURROGATEmacros occur in three different places. None of them interfere with 'normal' builds, but it does seem reasonable to define them in one place, namelycurspriv.h. They really shouldn't be defined for 8-bit (non-wide) builds, and now aren't. So doing caused me to see a place where the macros were used in 8-bit builds (harmlessly so, except that a few bytes of unnecessary code were generated). I fixed that. - The 'event_counts' variable was, as you noted, shadowed. However, it really should be a separate variable (the intent is not to modify the version of that variable that's static to 'pdckbd.c'.) Using the same name is not really a big deal, but it does trigger a warning in Visual C (in gcc and clang, it doesn't).
I'm a strong proponent of treating warnings as errors. Turns out that the Makefiles for Microsoft's compiler for WinCon and WinGUI lacked the -WX flag. So the warning was slipping by unobserved. I've fixed that.
an extremely unusual way of doing things.
Several projects do this; e.g. Mongoose and SqLite.
Almost any library built in this manner will break.
Pure speculation. My program with this amalgamation.c works fine.
PS. A problem with IS_SURROGATE(x). If <winnls.h> is ahead of curspriv.h, it wont be defined.
The difference is: some libraries have an amalgamation "one header instead of a static library" option, so far PDCurses did not. Bill was talking about applications using "normal style" library code, doing the amalgamation part on its own, like you did here.
I think the original issues are all solved and we may close this issue as fixed, right?
A possible followup question would be if we'd want to add official amalgamation support:
- a new define for makefiles (possibly also for cmake)
- this one would create a pdcurses.c file (if needed per timestamps), similar to what SqLite does and for the demos use this instead of the library
... but that discussion and tracking may be moved to a separate issue.