Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

2 bytes (16 bits) datatype, anyone?

+3 votes
asked Jun 13 by Riccardo Dell'Oro (150 points)
I'm using OnlineGDB compiler to test routines for embedded micros, where usual datatypes are:

'int8_t' and 'uint8_t', AKA 'char' and 'unsigned char', 1 byte-wide...

'int16_t' and 'uint16_t', AKA 'int' and 'unsigned int', 2 byte-wide...

'int32_t' and 'uint32_t', AKA 'double' and 'unsigned double' (sometimes referred to as 'long' and 'unsigned long'...), 4 byte-wide...

Apparently, OnlineGDB in "C" mode only supports 1 byte-wide (as 'char/uchar') and 4 byte-wide (as 'int/uint') datatypes (probably because aimed at the PC world) so before creating my own structure-based datatype, I would like to know if I'm missing something...

Any help appreciated, thanks.

1 Answer

+1 vote
answered Jun 14 by Shawn Armstrong (310 points)
I think you might have some confusion related to memory allocation for data types.

The C standard does not specify how many bits a specific data type is; thus, it is essentially left up to the operating system.

A long on a Windows 64-bit system is 4 bytes.

A long on Unix / Linux 64-bit system is typically 8 bytes.

This is why we have cstdint.h; it standardizes the number of bits for a particular data type regardless of your operating system enabling applications to be portable between different operating systems.

OnlineGDB is a Linux based system.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.