portability

GetThreadId on pre-vista systems?

天大地大妈咪最大 提交于 2019-11-30 20:09:50
Apperantly, GetThreadId is a Vista API. How can I get a thread's id on pre vista systems? Reed Copsey There are a few options: When you call CreateThread , you get the handle back. You can call GetCurrentThreadId to get the current thread's ID. You can use Thread32First / Thread32Next to enumerate threads. If you can somehow make the thread in question call GetCurrentThreadId and store it somewhere, you could read the result. If the thread in question enters an alertable wait state frequently, you could send it an APC with QueueUserAPC ; the APC handler can then call GetCurrentThreadId and

Using Powershell to Print a Folder of Text files to PDF (Retaining the Original Base name)

一世执手 提交于 2019-11-30 20:01:28
问题 First time posting - but I think this is a good one as I've spent 2 days researching, talked with local experts, and still haven't found this done. Individual print jobs must be regularly initiated on a large set of files (.txt files), and this must be converted through the print job to a local file (i.e. through a PDF printer) which retains the original base name for each file. Further, the script must be highly portable. The objective will not be met if the file is simply converted (and not

Does an empty string contain an empty string in C++?

故事扮演 提交于 2019-11-30 17:43:25
问题 Just had an interesting argument in the comment to one of my questions. My opponent claims that the statement "" does not contain "" is wrong. My reasoning is that if "" contained another "" , that one would also contain "" and so on. Who is wrong? P.S. I am talking about a std::string P.S. P.S I was not talking about substrings, but even if I add to my question " as a substring", it still makes no sense. An empty substring is nonsense . If you allow empty substrings to be contained in

Reproducibility of java pseudo-random numbers across systems and versions?

帅比萌擦擦* 提交于 2019-11-30 17:43:19
I need to generate a controlled sequence of pseudo-random numbers, given an initial integer parameter. For that I'm using the standard Java Random class, seeded by an integer parameter. I'd like to make sure that I will generate the same sequence across systems (Operating system, but also Java/JDK version), in the foreseeable future (and more!). In summary: Does Java ensure the reproducibility / portability of it's pseudo-random number generator across implementation and versions ? Note: I've asked the exact same question for Python . I since changed the implementation language to Java but for

How do I get the current user in Perl in a portable way?

陌路散爱 提交于 2019-11-30 17:42:50
How does one get the current user in a portable way? This seems like an FAQ but perlport doesn't speak about it, maybe because some odd systems don't have the concept of "user" to being with? However, let's stick to *nix and Windows. getpwuid($>) is not implemented on Windows. $ENV{USER} || $ENV{USERNAME} seems finicky. http://search.cpan.org didn't turn up much. getlogin : This implements the C library function of the same name, which on most systems returns the current login from /etc/utmp, if any. If null, use "getpwuid". $login = getlogin || getpwuid($<) || "Kilroy"; Do not consider

Recommended ways to produce app portable between Android and “other platforms”

北战南征 提交于 2019-11-30 17:25:51
I'm developing an application for Android, and I'm thinking that it's functionality might be useful on other (Java-running) platforms (say a regular desktop app -- although I hope that the other platform(s) involved are immaterial to the question at hand). It's unlikely that the UI will be in any way portable (there's just too much of a difference between a good touch-capable, 4in screen UI, and a mouse-and-keyboard 19in screen UI), so I'm happy enough reimplementing that separately. However, the core "business logic" (ugh, horrid word) and model (data storage) classes could, in theory, be

C/C++ algorithm to produce same pseudo-random number sequences from same seed on different platforms? [duplicate]

人盡茶涼 提交于 2019-11-30 15:58:50
This question already has an answer here: Consistent pseudo-random numbers across platforms 6 answers The title says it all, I am looking for something preferably stand-alone because I don't want to add more libraries. Performance should be good since I need it in a tight high-performance loop. I guess that will come at a cost of the degree of randomness. Any particular pseudo-random number generation algorithm will behave like this. The problem with rand is that it's not specified how it is implemented. Different implementations will behave in different ways and even have varying qualities.

Portable lightweight C++ sockets wrapper

别等时光非礼了梦想. 提交于 2019-11-30 14:39:01
问题 I really thought this would be easier to find... I need a portable c++ sockets wrapper. I'm planning to use it for a windows server application and a client that will be running on a embedded device running ulinux (or something similar). I would use Boost but I need it to be lightweight and easy to add to the embedded device project. Also I would like it to be a "higher level" wrapper... so it starts a background thread to read data and informs be over a callback... Any ideas? 回答1: Just learn

How to declare a variable as thread local portably?

谁说胖子不能爱 提交于 2019-11-30 13:08:39
C11 introduces the _Thread_local storage class specifier that can be used in combination with the static and extern storage class specifiers to declare a variable as thread local. The GNU C compiler suite implements a storage class specifier __thread with the same same semantics. Unfortunately I did not find any compiler (I tried gcc, clang and SUN studio) that actually implements the _Thread_local keywords. I currently use the following construct to declare a keyword thread_local : /* gcc doesn't know _Thread_local from C11 yet */ #ifdef __GNUC__ # define thread_local __thread #elif __STDC

C++ integral constants + choice operator = problem!

天涯浪子 提交于 2019-11-30 13:01:22
I have recently discovered an annoying problem in some large program i am developing; i would like to understand how to fix it in a best way. I cut the code down to the following minimal example. #include <iostream> using std::cin; using std::cout; class MagicNumbers { public: static const int BIG = 100; static const int SMALL = 10; }; int main() { int choice; cout << "How much stuff do you want?\n"; cin >> choice; int stuff = (choice < 20) ? MagicNumbers::SMALL : MagicNumbers::BIG; // PROBLEM! cout << "You got " << stuff << "\n"; return 0; } I get link errors in gcc 4.1.2 when compiling with