Datatypes Used in libsxe: 64 Bit Programming

libsxe uses standard C data types, but it is very careful to use them intentionally. We normally use the following types:

Type           | Defined     | Description
bool           | <stdbool.h> | Boolean values (true and false)
char           | C standard  | Printable characters
int            | C standard  | Integers that can be negative
size_t         | <stddef.h>  | Unsigneds the size of address space
uint8_t        | <stdint.h>  | Arbitrary octet values
uint16_t       | <stdint.h>  | Arbitrary 16 bit values
uint32_t       | <stdint.h>  | Arbitrary 32 bit values
uint64_t       | <stdint.h>  | Arbitrary 64 bit values
uintptr_t      | <stdint.h>  | Unsigneds the size of a pointer
unsigned       | C standard  | Usual non-negative integers
void *         | C standard  | Typeless pointers
wchar_t        | <wchar.h>   | Wide characters; used on Windows

To ensure that these types can be formatted, we use the following formats:

Type      | Format[/Conversion]    | Defined      | Description
bool      | %s/sxe_bool_to_string  |              | true/false value
char      | %c                     | printf       | Printable character
char *    | %s                     | printf       | Printable string
int       | %d                     | printf       | Signed integer
size_t    | %"PRIuPTR"/(uintptr_t) | <inttypes.h> | Mem sized unsigned
uint8_t   | %02x,%u                | printf       | Unsigned octet
uint16_t  | %04x,%hu               | printf       | Unsigned 16 bit
uint32_t  | %"PRIx32",%"PRIu32"    | <inttypes.h> | Unsigned 32 bit
uint64_t | %"PRIx64",%"PRIu64"     | <inttypes.h> | Unsigned 64 bit
uintptr_t | %p,%"PRIuPTR"          | <inttypes.h> | Ptr sized unsigned
unsigned  | %x,%u                  | printf       | Usual unsigned
void *    | %p                     | printf       | Typeless pointer

Note that the size_t type does not have a portable (32 to 64 bit) format on Windows. We tend to avoid using size_t, preferring unsigned unless the size can exceed 2^32. If you have a true size_t, it can be cast to a (uintptr_t) to be safely printed.

About jimbelton

I'm a software developer, and a writer of both fiction and non-fiction, and I blog about movies, books, and philosophy. My interest in religious philosophy and the search for the truth inspires much of my writing.
This entry was posted in programming and tagged , , , , . Bookmark the permalink.

2 Responses to Datatypes Used in libsxe: 64 Bit Programming

  1. Samuel Koh says:

    I stumbled on libsxe and read Simon’s blog. One thing led to another as I was learning, from nodejs to lua and then here and libsxe is making me smile.

    I’m not on a mega-load project but planning one which could potentially see the load coming up quite fast.

    I would be great to see more tutorials and sample codes on getting started with libsxe http servers and such. I believe you will have an audience beyond low level geeks.

    • jimbelton says:

      Libsxe is something that Simon, Neil, Lucas and I and several others have been able to slowly build up as part of our jobs at Sophos. We are mainly doing stuff we need in our work, but we have a bit of spare time to hack on other stuff. We are planning to put more tutorials on Also, Simon has been planning to do a chat server sample application. Lately I’ve been hacking on a documentation generator (the first version of it is in the mak/bin/ script).

      My current spare time coding is on an experimental memory allocator, which is more “low level geek” stuff, but may be pretty cool once its done. Neil’s branch has openssl support. He wrote the original sxe-httpd server package, and we’ve both continued to extend it. Lucas had some “sxe for dummies” beginner tutorials on his blog, but I don’t think it’s linked from I’ll ask him about it tomorrow.

Leave a Comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s