Skip to content

[R-pkg-devel] AlgDesign C Issue

6 messages · Michael Chirico, Jerome Braun, Duncan Murdoch

#
Hi!

I'm currently the maintainer of AlgDesign, though my C skill is clearly a
little too low for the task.

It has become necessary for me to fix some issues with the code that had
defined true, false, and bool in the header file (wheeler.h).

Lines 23 and 24 currently have:

#define true 1
#define false 0

There used to be a line 25 that had:

#define bool int

I removed line 25 and changed all occurrences in the C code of "bool" to
"int".   But this doesn't seem to have fully resolved the issue.

The current checks on AlgDesign generate a warning based on header lines 23
and 24:

Debian: <
https://win-builder.r-project.org/incoming_pretest/AlgDesign_1.2.1.2_20250331_023833/Debian/00check.log
Status: 1 WARNING, 1 NOTE

I'm not sure what this means yet, nor how to resolve it properly.  I would
love some help in working forward, if possible.

Thank you very much!
#
Do you want to use <stdbool.h> instead of your macros?

https://pubs.opengroup.org/onlinepubs/009695399/basedefs/stdbool.h.html

On Mon, Mar 31, 2025, 12:37?AM Jerome Braun <jvbraun.statistics at gmail.com>
wrote:

  
  
#
Hi Michael!

I'd like to make the smallest change possible to Bob Wheeler's original
code so I'm not sure if using <stdbool.h> is the best route forward.

I do see that the definitions are the same there.  Is there a low-cost way
to use that header file or just those definitions?

Thank  you!
#
On 2025-03-31 9:28 a.m., Jerome Braun wrote:
The problem is that the definitions may vary from compiler to compiler, 
and the error message you're getting only shows up some of them.  Since 
the compiler will supply stdbool.h, it's safer to use that than to try 
to emulate it.

Duncan Murdoch
#
Hi Duncan!
try to emulate it.

Understood. It seems like the definitions are exactly the same between the
two.

Currently there is no use of "bool" in any of the code (after having
changed bool to int everywhere in the code).

So I think I can replace the two lines in the original code with a call to
include the <stdbool.h> header --- does that seem reasonable?   Can I use
an include statement there in place of those two lines?

Thank you!
#
On 2025-03-31 12:00 p.m., Jerome Braun wrote:
I think replacing those two defines with

#include <stdbool.h>

should be safe.  There's not much a huge difference between bool and 
int, but they aren't the same, so you might still run into some issues. 
For example, in a modern C compiler a bool value can never be 
NA_LOGICAL, but an int value could be.  And if you do arithmetic on bool 
values, you might be surprised by the answer.  For example

   bool x = true + true;

results in x storing true, which is equivalent to 1 when used as an integer.

Duncan Murdoch