Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8283881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:54:02+00:00 2026-06-08T10:54:02+00:00

As far as I know, the C library provides no help in serializing numeric

  • 0

As far as I know, the C library provides no help in serializing numeric values into a non-text byte stream. Correct me if I’m wrong.

The most standard tool in use is htonl et al from POSIX. These functions have shortcomings:

  • There is no 64-bit support.
  • There is no floating-point support.
  • There are no versions for signed types. When deserializing, the unsigned-to-signed conversion relies on signed integral overflow which is UB.
  • Their names do not state the size of the datatype.
  • They depend on 8-bit bytes and the presence of exact-size uint_N_t.
  • The input types are the same as the output types, instead of referring to a byte stream.
    • This requires the user to perform a pointer typecast which is possibly unsafe in alignment.
    • Having performed that typecast, the user is likely to attempt to convert and output a structure in its native memory layout, a poor practice which results in unexpected errors.

An interface for serializing arbitrary-size char to 8-bit standard bytes would fall in between the C standard, which doesn’t really acknowledge 8-bit bytes, and whatever standards (ITU?) set the octet as the fundamental unit of transmission. But the older standards aren’t getting revised.

Now that C11 has many optional components, a binary serialization extension could be added alongside things like threads without placing demands on existing implementations.

Would such an extension be useful, or is worrying about non-two’s-complement machines just that pointless?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T10:54:03+00:00Added an answer on June 8, 2026 at 10:54 am

    I’ve never used them, but I think Google’s Protocol Buffers satisfy your requirements.

    • 64 bit types, signed/unsigned, and floating point types are all supported.
    • The API generated is typesafe
    • Serialisation can be done to/from streams

    This tutorial seems like a pretty good introduction, and you can read about the actual binary storage format here.


    From their web page:

    What Are Protocol Buffers?

    Protocol buffers are Google’s language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler. You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages – Java, C++, or Python.

    There’s no official implementation in pure C (only C++), but there are two C ports that might fit your needs:

    • Nanopb, at http://koti.kapsi.fi/jpa/nanopb/

    • Protobuf-c at http://code.google.com/p/protobuf-c/

    I don’t know how they fare in the presence of non-8 bit bytes, but it should be relatively easy to find out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i will be short. As far as i know watir library provides two methods
As far as I know, the support for library://ns.adobe.com/flex/halo namespace has been dropped, and
So far I know that FileSystemWatcher can look into a folder and if any
As far as know, I must be careful with PHP, and I think Javascript.
as far as I know both 2012-07-04T17:30:52+00:00 and 2012-07-04T17:30:52Z are dates in iso8601 format
As far as I know there is no way to migrate existing Facebook comments
As far as I know, C2DM is per app per device thing..but my question
As far as I know, Timer runs asynchronously, so If a very short duration
As far as I know that JSF keeps all the session scoped bean in
As far as I know, VisualSVN Server is a server while TortoiseSVN is a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.