portability

Choice of language for portable library

为君一笑 提交于 2019-12-23 15:25:46
问题 I want to write a library which will be dynamically linked from other programs running on modern operating systems like Windows, Linux and OS/X (i.e. it will be deployed as a .dll or .so module). What is the most appropriate language in that case? Should I stick with plain C? Or is C++ also ok? 回答1: You can use either C or C++ for the implementation, but I would recommend to define the interface in pure C. It will be much easier to integrate. 回答2: The difficulty with creating a C++ library

How to use generics in a world of mixed Java versions?

我们两清 提交于 2019-12-23 15:22:44
问题 I like generics a lot and use them whereever I can. Every now and then I need to use one of my classes in another project which has to run on an old JVM (before 5.0), needs to run on JavaME (where generics are not allowed neither) or in Microsoft J# (which has VERY poor Support for generics). At the moment, I remove all generics manually, which means inserting many casts as well. Since generics are said to be compile-time-only, and every piece of generic code could possibly converted to non

Is there a portable way to give thread name with Qt?

一个人想着一个人 提交于 2019-12-23 11:14:08
问题 I know I can set thread name (the one visible in gdb and htop) in Linux using prctl(). But with another OSes this most likely won't work. Also, I could try using pthread_setname_np(), which is a bit more available across POSIX systems, but still lacks full compatibility. So I'd like to have some more portable way, maybe something QThread provides which I've not found. Is there any such way? 回答1: There's nothing in the QThread API to manually manage the system name of the thread, however,

Portable JDBC vs SQLite on Android

不想你离开。 提交于 2019-12-23 09:39:49
问题 I am using SQLite in a project used by an android application. Currently I am using the SQLite implementation provided in android.database.sqlite . I want to make a desktop application which uses the same codebase. So I need to separate all the shared behaviour into a separate portable project/jar. My problem is I'm currently making heavy use of android.database.sqlite . If possible I do not want to re-write every database access call to be compatible with JDBC or whatever I will have to use

To which extent is “boost does it” equivalent to “very portable, use it”?

China☆狼群 提交于 2019-12-23 08:51:02
问题 In this answer to a question asking "is doing Z this way portable" the idea is "boost does it this way, it means it is very portable". Can I just always consult boost sources to find the most portable way of doing something in C++? How can I judge for myself if boost is really such a collection of super-portable code? 回答1: There are some cases where Boost libraries exist precisely because they wrap very non-portable code. The most obvious examples are the file system and threading stuff. The

Is using pattern names starting with “_” (underscore) for ignored results documented/encouraged/portable?

感情迁移 提交于 2019-12-23 06:57:09
问题 Let's say I want to fork a thread within a do -notation block, but I don't care about the thread id. If I write forkIO action GHC issues warning Warning: A do -notation statement discarded a result of type ThreadId . Suppress this warning by saying _ <- forkOS action This is a good idea as I want to show that the program is discarding some result. However, this way it won't be apparent what's being discarded. I could write threadId <- forkIO action but then we're hiding the fact that we won't

Is this C++ code portable? (assuming multidimensional arrays have continuous memory layout)

蓝咒 提交于 2019-12-23 06:50:13
问题 First of all, sorry for my english if i make any grammar mistakes, etc ... My question is, that when we have a two dimensional array, then if i am right, from the point of the computer and C/C++, it's just a long one dimensional array, the indices are just helping the compiler to map to the concrete address. This code fragment works in Visual C++, however I would like to know, whether this code is portable and conforms to the standard (C++98), not causing surprises on other architectures and

Portable end of line

ぃ、小莉子 提交于 2019-12-23 06:49:18
问题 is there any way to automatically use correct EOL character depending on the OS used? I was thinking of something like std::eol ? I know that it is very easy to use preprocessor directives but curious if that is already available. What I am interested in is that I usually have some messages in my applications that I combine later into a single string and I want to have them separated with a EOL. I know that I could use std::stringstream << endl but it seems to be an overkill sometimes instead

How to limit the execution time of a function in C/POSIX?

喜欢而已 提交于 2019-12-22 19:30:22
问题 Similar to this question, I'd like to limit the execution time of a function--preferably with microsecond accuracy--in C. I imagine that C++ exceptions could be used to achieve a result similar to this Python solution. Though it's not ideal, such an approach is wholly unavailable in plain C. I wonder, then, how might I interrupt the execution of a function after a certain time interval in C on a Posix system? For relatively simple situations a bit of silly business works just fine, but that

Making portable code

大兔子大兔子 提交于 2019-12-22 09:45:36
问题 With all the fuss about opensource projects, how come there is still not a strong standard that enables you to make portable code (I mean in C/C++ not Java or C# ) Everyone is kind of making it's own soup. There are even some third party libs like Apache Portable Runtime . 回答1: Yes, there is no standard but libraries like Qt and boost can make your life much easier when you do cross-platform development. 回答2: wxwidgets is a great abstraction layer on the native GUI widgets of most window