portability

Why does this simple threaded program get stuck?

流过昼夜 提交于 2019-12-05 20:28:27
Take a look at this simple Java program: import java.lang.*; class A { static boolean done; public static void main(String args[]) { done = false; new Thread() { public void run() { try { Thread.sleep(1000); // dummy work load } catch (Exception e) { done = true; } done = true; } }.start(); while (!done); System.out.println("bye"); } } On one machine, it prints "bye" and exits right away, while on another machine, it doesn't print anything and sits there forever. Why? This is because your boolean is not volatile , therefore Thread s are allowed to cache copies of it and never update them. I

Aren't ASCII values of 'a' to 'z' consecutive from 97 to 122 irrespective of implementation? A good book says otherwise [duplicate]

北战南征 提交于 2019-12-05 20:07:58
This question already has an answer here: Who determines the ordering of characters 6 answers I see nothing wrong with the following program, and this being non-portable is really confusing to me. According to the book by Mike Banahan (GBdirect C Book, Section 2.4.2) , the following program is non-portable. Reason given is: Another example, perhaps. This will either print out the whole lower case alphabet, if your implementation has its characters stored consecutively, or something even more interesting if they aren't. C doesn't make many guarantees about the ordering of characters in internal

Django Reusable Application Configuration

时光总嘲笑我的痴心妄想 提交于 2019-12-05 19:24:46
I have some Django middleware code that connects to a database. I want to turn the middleware into a reusable application ("app") so I can package it for distribution into many other projects, without needing to copy-and-paste. I don't understand where a reusable application is supposed to configure itself. Since it's intended for redistribution I don't have the ability to write the central settings.py myself. Looking at the Django documentation I see there's settings.configure but it appears to replace the entire configuration, instead of letting me "splice" a new database into DATABASES.

SQLAlchemy: How to conditionally choose type for column by depending on its backend

依然范特西╮ 提交于 2019-12-05 19:02:03
问题 I want to use HSTORE type for a column if it uses PostgreSQL as its backend, or PickleType otherwise. The problem is that we cannot determine which backend will be used when schema is being defined (in Python). How can I determine this and conditionally choose the data type when the table actually is created on the backend database? 回答1: You can accomplish something like this with TypeEngine.with_variant: from sqlalchemy.types import PickleType from sqlalchemy.dialects import postgresql

How to determine C code is compiled for Android/NDK or iOS

孤街醉人 提交于 2019-12-05 16:54:50
问题 I am reusing a legacy C library in an iOS app and in an Android app. I want to customize some macro definitions (e.g. for logging). Are there standard defines to check for (using #ifdef) whether the code is being compiled for iOS or Android/NDK? 回答1: __ANDROID__ or ANDROID for Android (compilation with the NDK) and __APPLE__ on Apple platforms (iOS or OSX) 回答2: you should consider creating two separate projects for those platforms with separate output/bin directories but shared source code.

C++ Process Management [closed]

自古美人都是妖i 提交于 2019-12-05 14:32:47
Is there a well-known, portable, good library for C++ process management? I found a promising library called Boost.Process , but it's only a candidate for inclusion in the Boost library. Has anyone use this? Does anyone know why it isn't a part of Boost? How much management do you need? Just fork/exec? IPC? Resource management? Security contexts and process isolation ? I haven't used the Boost.Process library. However, I do know that getting included in Boost is a rather difficult affair. Boost recently accepted a futures library that had already been approved as part of the standard. However,

What parts of C are most portable?

拈花ヽ惹草 提交于 2019-12-05 11:37:19
问题 I recently read an interview with Lua co-creators Luiz H. de Figueredo and Roberto Ierusalimschy, where they discussed the design, and implementation of Lua. It was very intriguing to say the least. However, one part of the discussion brought something up in my mind. Roberto spoke of Lua as a " freestanding application " (that is, it's pure ANSI C that uses nothing from the OS.) He said, that the core of Lua was completely portable, and because of its purity has been able to be ported much

How portable is code with #pragma optimize?

隐身守侯 提交于 2019-12-05 10:45:14
How portable is code that uses #pragma optimize ? Do most compilers support it and how complete is the support for this #pragma ? #pragma is the sanctioned and portable way for compilers to add non-sanctioned and non-portable language extensions * . Basically, you never know for sure, and at least one major C++ compiler (g++) does not support this pragma as is. * : From the C++ standard (N3242): 16.6 Pragma directive [cpp.pragma] A preprocessing directive of the form # pragma pp-tokens opt new-line causes the implementation to behave in an implementation-defined manner. The behavior might

How portable is __get_cpuid?

为君一笑 提交于 2019-12-05 08:48:42
I'm using __get_cpuid() to get info on the x86 and x86_64 processors my programs run on. With GCC on Linux and Mac OS, it seems to compile and run OK without include any header, but how portable is that? Would it work with other compilers? Should I include a header for that? It has two leading underscores. Any leading underscore at all is a big hint that the variable or function is not portable. 来源: https://stackoverflow.com/questions/8407001/how-portable-is-get-cpuid

What contraints should I be aware of to maximize portability of Mono code?

删除回忆录丶 提交于 2019-12-05 05:35:44
I'm interested in writing some cross-platform code using Mono, with a view to targeting mobile iOS and Android runtimes. I've perused the Mono and MonoTouch sites, but don't see anything that specifically advises on methods not to use, or Mono hooks which should be avoided. However, that seems a little too good to be true. What limitations should I be aware of going into this project, to ensure maximum portability of the code? API wise you get a very similar base class libraries (BCL) when using MonoTouch or Mono for Android (M4A) since both share the same mobile profile (which was originally