portability

Portable serialisation of IEEE754 floating-point values

北城以北 提交于 2019-11-27 23:36:31
问题 I've recently been working on a system that needs to store and load large quantities of data, including single-precision floating-point values. I decided to standardise on network byte order for integers, and also decided to store floating point values in big-endian format, i.e.: |-- Byte 0 --| |-- Byte 1 -| Byte 2 Byte 3 # ####### # ####### ######## ######## Sign Exponent Mantissa 1b 8b, MSB first 23b, MSB first Ideally, I want to provide functions like htonl() and ntohl() , since I have

C++ Class wrapper around fundamental types

你说的曾经没有我的故事 提交于 2019-11-27 22:25:30
Many libraries I have seen/used have typedefs to provide portable, fixed size variables, eg int8, uint8, int16, uint16, etc which will be the correct size regardless of platform (and c++11 does it itself with the header stdint.h) After recently using binary file i/o in a small library I'm writing I can see the benefit of using typedefs in this way to ensure the code is portable. However, if I'm going to the trouble of typing "namespace::uint32" rather than using built in fundamental types, I may as well make the replacement as useful as possible. Therefore I am considering using classes

What's the difference between “int” and “int_fast16_t”?

大城市里の小女人 提交于 2019-11-27 20:23:24
As I understand it, the C specification says that type int is supposed to be the most efficient type on target platform that contains at least 16 bits. Isn't that exactly what the C99 definition of int_fast16_t is too? Maybe they put it in there just for consistency, since the other int_fastXX_t are needed? Update To summarize discussion below: My question was wrong in many ways. The C standard does not specify bitness for int . It gives a range [-32767,32767] that it must contain. I realize at first most people would say, "but that range implies at least 16-bits!" But C doesn't require two's

How to Declare a 32-bit Integer in C

非 Y 不嫁゛ 提交于 2019-11-27 19:57:15
What's the best way to declare an integer type which is always 4 byte on any platforms? I don't worry about certain device or old machines which has 16-bit int . #include <stdint.h> int32_t my_32bit_int; nos C doesn't concern itself very much with exact sizes of integer types, C99 introduces the header stdint.h , which is probably your best bet. Include that and you can use e.g. int32_t . Of course not all platforms might support that. Corey's answer is correct for "best", in my opinion, but a simple "int" will also work in practice (given that you're ignoring systems with 16-bit int). At this

Free portable database [closed]

三世轮回 提交于 2019-11-27 19:46:23
Hi I am developing desktop portable free application and I`m looking for portable database: free without install up to 20K records standalone application supports encryption (optional) SQL92 spec thanks for advice can you write some advantages and disadvangtages? SQLite: self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world. The source code for SQLite is in the public domain. -Adam Firebird embedded About: Firebird is an open source relational database offering many ANSI SQL-99 features that runs

GLIBCXX versions

谁都会走 提交于 2019-11-27 18:59:50
If I compile a C++ program on my machine, and run it on another one (with older software) I get: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.9' not found . In fact on my system glibc is newer (I got gcc-libs 4.5.1: libstdc++.so.6.0.14) and strings /usr/lib/libstdc++.so.6 | grep GLIBCXX prints from GLIBCXX_3.4 to GLIBCXX_3.4.14 . On the other system, instead, it only prints up to GLIBCXX_3.4.8 (I got libstdc++.so.6.0.8). So I've got a few questions: Why my linker links C++ binaries against libstdc++ version GLIBCXX_3.4.9 instead of GLIBCXX_3.4.14 ? If I complied my binary against libstdc++

Using Python's ftplib to get a directory listing, portably

故事扮演 提交于 2019-11-27 18:06:07
You can use ftplib for full FTP support in Python. However the preferred way of getting a directory listing is: # File: ftplib-example-1.py import ftplib ftp = ftplib.FTP("www.python.org") ftp.login("anonymous", "ftplib-example-1") data = [] ftp.dir(data.append) ftp.quit() for line in data: print "-", line Which yields: $ python ftplib-example-1.py - total 34 - drwxrwxr-x 11 root 4127 512 Sep 14 14:18 . - drwxrwxr-x 11 root 4127 512 Sep 14 14:18 .. - drwxrwxr-x 2 root 4127 512 Sep 13 15:18 RCS - lrwxrwxrwx 1 root bin 11 Jun 29 14:34 README -> welcome.msg - drwxr-xr-x 3 root wheel 512 May 19

OS specific instructions in CMAKE: How to?

安稳与你 提交于 2019-11-27 17:16:52
I am a beginner to CMAKE. Below is a simple cmake file which works well in mingw environment windows. The problem is clearly with target_link_libraries() function of CMAKE where I am linking libwsock32.a. In windows this works and I get the results. However, as expected, in Linux, the /usr/bin/ld will look for -lwsock32 which is NOT there on the Linux OS. My Problem is: How do I instruct CMAKE to avoid linking wsock32 library in Linux OS??? Any help will be greatly appreciated. My Simple CMake file: PROJECT(biourl) set (${PROJECT_NAME}_headers ./BioSocketAddress.h ./BioSocketBase.h .

How to print types of unknown size like ino_t?

淺唱寂寞╮ 提交于 2019-11-27 17:15:27
问题 I often experience situations where I want to print with printf the value of an integer type of implementation-defined size (like ino_t or time_t ). Right now, I use a pattern like this for this: #include <inttypes.h> ino_t ino; /* variable of unknown size */ printf("%" PRIuMAX, (uintmax_t)ino); This approach works so far but it has a couple of disadvantages: I have to know whether the type I'm trying print is signed or unsigned. I have to use a type cast that possibly enlarges my code. Is

In C/C++, are volatile variables guaranteed to have eventually consistent semantics betwen threads?

自闭症网瘾萝莉.ら 提交于 2019-11-27 16:20:21
问题 Is there any guarantee by any commonly followed standard (ISO C or C++, or any of the POSIX/SUS specifications) that a variable (perhaps marked volatile), not guarded by a mutex, that is being accessed by multiple threads will become eventually consistent if it is assigned to? To provide a specific example, consider two threads sharing a variable v, with initial value zero. Thread 1: v = 1 Thread 2: while(v == 0) yield(); Is thread 2 guaranteed to terminate eventually? Or can it conceivably