# Why is igraph\_bool\_t an int and not a char?

**URL:** <https://igraph.discourse.group/t/why-is-igraph-bool-t-an-int-and-not-a-char/126>\
**Category:** Development\
**Tags:** C\
**Created:** [3 March 2020 14:37 UTC](https://igraph.discourse.group/t/why-is-igraph-bool-t-an-int-and-not-a-char/126 "2020-03-03T14:37:02Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [3 March 2020 14:37 UTC](https://igraph.discourse.group/t/why-is-igraph-bool-t-an-int-and-not-a-char/126/1 "2020-03-03T14:37:02Z")

</div>

I think I may have brought this up some years ago, but I do not remember the discussion.

Why is `igraph_bool_t` defined as an `int` and not as a (space efficient) `char`?

---

<div class="post-metadata">

**Author:** ![vtraag](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/vtraag/32/38_2.png) [@vtraag](https://igraph.discourse.group/u/vtraag)\
**Post date:** [3 March 2020 16:20 UTC](https://igraph.discourse.group/t/why-is-igraph-bool-t-an-int-and-not-a-char/126/2 "2020-03-03T16:20:09Z")

</div>

I believe this was because R uses `int`s for Booleans. Probably @Gabor can tell more about this.

---

<div class="post-metadata">

**Author:** ![Gabor](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/gabor/32/15_2.png) [@Gabor](https://igraph.discourse.group/u/Gabor)\
**Post date:** [3 March 2020 16:30 UTC](https://igraph.discourse.group/t/why-is-igraph-bool-t-an-int-and-not-a-char/126/3 "2020-03-03T16:30:52Z")

</div>

Yes, that’s correct.

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [3 March 2020 16:44 UTC](https://igraph.discourse.group/t/why-is-igraph-bool-t-an-int-and-not-a-char/126/4 "2020-03-03T16:44:30Z")

</div>

We already have `igraph_vector_char_t` and similar.

Then I can use `igraph_vector_bool_t` for public APIs but use `igraph_vector_char_t` for purely internal boolean vectors, to save storage.

Sounds reasonable?

I guess I could also use a raw `char *` but that’s a pain to deal with.

---

<div class="post-metadata">

**Author:** ![vtraag](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/vtraag/32/38_2.png) [@vtraag](https://igraph.discourse.group/u/vtraag)\
**Post date:** [3 March 2020 19:03 UTC](https://igraph.discourse.group/t/why-is-igraph-bool-t-an-int-and-not-a-char/126/5 "2020-03-03T19:03:29Z")

</div>

I think that is a reasonable approach. Semantically it might be more appropriate to have something like `igraph_i_boolean_t`, but that is not necessary.

---

<div class="post-metadata">

**Author:** ![vtraag](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/vtraag/32/38_2.png) [@vtraag](https://igraph.discourse.group/u/vtraag)\
**Post date:** [3 March 2020 19:07 UTC](https://igraph.discourse.group/t/why-is-igraph-bool-t-an-int-and-not-a-char/126/6 "2020-03-03T19:07:12Z")

</div>

We could even consider a `igraph_bit_vector_t` type which uses individual bits (and of course uses the most appropriate underlying `int` type), instead of entire `chars`, but that might involve more work to do properly, especially for vector operations.

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [22 July 2020 11:55 UTC](https://igraph.discourse.group/t/why-is-igraph-bool-t-an-int-and-not-a-char/126/7 "2020-07-22T11:55:02Z")

</div>

@Gabor What about `igraph_integer_t` being `int`? Is that also restricted by the R interface, or is it feasible to change it?

It would be convenient to make it 32-bit on 32-bit platforms and 64-bit on 64-bit platforms.

---

<div class="post-metadata">

**Author:** ![Gabor](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/gabor/32/15_2.png) [@Gabor](https://igraph.discourse.group/u/Gabor)\
**Post date:** [22 July 2020 12:07 UTC](https://igraph.discourse.group/t/why-is-igraph-bool-t-an-int-and-not-a-char/126/8 "2020-07-22T12:07:06Z")

</div>

It is not feasible to change it, I think, without a lot of work, and basically no gain? At least I don’t see the immediate gain.

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [27 July 2020 07:18 UTC](https://igraph.discourse.group/t/why-is-igraph-bool-t-an-int-and-not-a-char/126/9 "2020-07-27T07:18:24Z")

</div>

@Gabor I wrote up some of the reasons here: [https://github.com/igraph/igraph/issues/1450](https://github.com/igraph/igraph/issues/1450)

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [30 July 2020 07:10 UTC](https://igraph.discourse.group/t/why-is-igraph-bool-t-an-int-and-not-a-char/126/10 "2020-07-30T07:10:37Z")

</div>

@Gabor Could you please comment here? [https://github.com/igraph/igraph/issues/1450](https://github.com/igraph/igraph/issues/1450) See my last message.
