# Ffi: add fixed size type like int8\_t or \_Float16

**URL:** <https://swi-prolog.discourse.group/t/ffi-add-fixed-size-type-like-int8-t-or-float16/8545>\
**Category:** General\
**Created:** [October 18, 2024, 10:18am UTC](https://swi-prolog.discourse.group/t/ffi-add-fixed-size-type-like-int8-t-or-float16/8545 "2024-10-18T10:18:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kwon-young](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/kwon-young/32/4841_2.png) [@kwon-young](https://swi-prolog.discourse.group/u/kwon-young)\
**Post date:** [October 18, 2024, 10:18am UTC](https://swi-prolog.discourse.group/t/ffi-add-fixed-size-type-like-int8-t-or-float16/8545/1 "2024-10-18T10:18:51Z")

</div>

Hello,

I’m currently trying to implement an array library using the concept of strides like numpy.  
The basic idea of a strided array is to have a 1d buffer storing all the array elements and use views with a shape and stride to iterate the 1d buffer.

I would like to use the `c_alloc/2` predicate from the library [`ffi`](https://www.swi-prolog.org/pack/list?p=ffi) to allocate the 1d buffer for my arrays since it provides the code to make garbage collected blobs.  
But I would also like to use fixed sized integer and floating type, i.e. those defined in `stdint.h` like `int8_t` and `uint8_t` of all sizes and also the non standard fixed size floating type like `_Float16`.

I started to look at [ffi/c/cmemory.c at 39f34302ca9f0c8ef786241f216d93a965734455 · JanWielemaker/ffi · GitHub](https://github.com/JanWielemaker/ffi/blob/39f34302ca9f0c8ef786241f216d93a965734455/c/cmemory.c) and it seems that supporting these additional type is going to be quite hard/verbose.

@jan Would a pull-request be accepted if I add these types myself ?  
Or should I just reimplement `c_alloc` myself ?

---

<div class="post-metadata">

**Author:** ![kwon-young](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/kwon-young/32/4841_2.png) [@kwon-young](https://swi-prolog.discourse.group/u/kwon-young)\
**Post date:** [October 18, 2024, 1:05pm UTC](https://swi-prolog.discourse.group/t/ffi-add-fixed-size-type-like-int8-t-or-float16/8545/2 "2024-10-18T13:05:19Z")

</div>

Never mind, I have just implemented a foreign interface with a blob that holds N bytes.  
I think it is going to be enough for now.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [October 18, 2024, 1:56pm UTC](https://swi-prolog.discourse.group/t/ffi-add-fixed-size-type-like-int8-t-or-float16/8545/3 "2024-10-18T13:56:59Z")

</div>

If that is all you need, that is probably simpler than using the ffi module 🙂
