portability

When is the use of std::ref necessary?

拈花ヽ惹草 提交于 2019-11-29 05:28:09
问题 Consider: std::tuple<int , const A&> func (const A& a) { return std::make_tuple( 0 , std::ref(a) ); } Is the std::ref required for writing correct and portable code? (It compiles fine without it) Background: If I remove std::ref my code builds fine without any warnings ( g++-4.6 -Wall ), but doesn't run correctly. In case of interest the definition of A : struct A { std::array<int,2> vec; typedef int type_t; template<typename... OPs,typename... VALs> A& operator=(const std::pair< std::tuple

UINT_MAX + 1 equals what?

孤人 提交于 2019-11-29 03:53:28
What is the defined behavior in C for UINT_MAX + 1u ? How safe is to assume it is zero? From the standard (C11, 6.2.5/9, emphasis mine): [...] A computation involving unsigned operands can never overflow, because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting type . If UINT_MAX is 10 : (10 + 1) % (10 + 1) == 0 So, yes, it's safe to assume it's zero. paulsm4 It's worth emphasizing that while unsigned behavior is well-defined, signed integer overflow isn't:

How to deal with the most common classes missing on J2ME

只谈情不闲聊 提交于 2019-11-29 02:39:33
问题 I'm trying to code an application which runs un different java platforms like J2SE, J2ME, Android, etc. I already know that I'll have to rewrite most of the UI for each platform, but want to reuse the core logic. Keeping this core portable involves three drawbacks that I know of: Keeping to the old Java 1.4 syntax , not using any of the nice language features of Java 5.0 only using external libraries that are known to work on those platforms (that is: don't use JNI and don't have dependencies

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

本小妞迷上赌 提交于 2019-11-29 02:01:26
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 spin forever because the cache coherency never kicks in and makes the assignment visible in thread 2's

How do you write (portably) reverse network byte order?

自作多情 提交于 2019-11-29 02:01:02
Background When designing binary file formats, it's generally recommended to write integers in network byte order. For that, there are macros like htonhl() . But for a format such as WAV, actually the little endian format is used. Question How do you portably write little endian values, regardless of if the CPU your code runs on is a big endian or little endian architecture? (Ideas: can the standard macros ntohl() and htonl() be used "in reverse" somehow? Or should the code just test runtime if it's running on a little or big endian CPU and choose the appropriate code path?) So the question is

Does MS-SQL support in-memory tables?

前提是你 提交于 2019-11-29 01:25:42
Recently, I started changing some of our applications to support MS SQL Server as an alternative back end. One of the compatibility issues I ran into is the use of MySQL's CREATE TEMPORARY TABLE to create in-memory tables that hold data for very fast access during a session with no need for permanent storage. What is the equivalent in MS SQL? A requirement is that I need to be able to use the temporary table just like any other, especially JOIN it with the permanent ones. @Keith This is a common misconception: Table variables are NOT necessarily stored in memory. In fact SQL Server decides

Writing a portable C program - which things to consider?

自闭症网瘾萝莉.ら 提交于 2019-11-29 00:40:19
问题 For a project at university I need to extend an existing C application, which shall in the end run on a wide variety of commercial and non-commercial unix systems (FreeBSD, Solaris, AIX, etc.). Which things do I have to consider when I want to write a C program which is most portable? 回答1: The best advice I can give, is to move to a different platform every day, testing as you go. This will make the platform differences stick out like a sore thumb, and teach you the portability issues at the

Portable C++ Stack Trace on Exception

拜拜、爱过 提交于 2019-11-28 23:30:41
I am writing a library that I would like to be portable. Thus, it should not depend on glibc or Microsoft extensions or anything else that is not in the standard. I have a nice hierarchy of classes derived from std::exception that I use to handle errors in logic and input. Knowing that a particular type of exception was thrown at a particular file and line number is useful, but knowing how the execution got there would be potentially much more valuable, so I have been looking at ways of acquiring the stack trace. I am aware that this data is available when building against glibc using the

How should I handle “cast from ‘void*’ to ‘int’ loses precision” when compiling 32-bit code on 64-bit machine?

时间秒杀一切 提交于 2019-11-28 22:32:44
I have a package that compiles and works fine on a 32-bit machine. I am now trying to get it to compile on a 64-bit machine and find the following error- error: cast from ‘void*’ to ‘int’ loses precision Is there a compiler flag to suppress these errors? or do I have to manually edit these files to avoid these casts? Reed Copsey The issue is that, in 32bits, an int (which is a 32bit integer) will hold a pointer value. When you move to 64bit, you can no longer store a pointer in an int - it isn't large enough to hold a 64bit pointer. The intptr_t type is designed for this. Your code is broken.

Packaging Ruby into a portable executable

╄→гoц情女王★ 提交于 2019-11-28 22:17:03
问题 I have been trying to find a good solution to this for a long time: Is there a sure-fire way to install ruby to a folder which is portable on that platform? I want to have a folder which I can easily copy into a distribution I am making so I can have a ruby environment "on the go". It is fine if I need to compile the source and stuff, as long as I end up with a portable ruby install. I have found a few resources which tries to solve this, but none are satisfactory for me. Portable Ruby on