portability

Is there a replacement for unistd.h for Windows (Visual C)?

徘徊边缘 提交于 2019-11-26 01:49:00
问题 I\'m porting a relatively simple console program written for Unix to the Windows platform (Visual C++ 8.0). All the source files include \"unistd.h\", which doesn\'t exist. Removing it, I get complaints about misssing prototypes for \'srandom\', \'random\', and \'getopt\'. I know I can replace the random functions, and I\'m pretty sure I can find/hack-up a getopt implementation. But I\'m sure others have run into the same challenge. My question is: is there a port of \"unistd.h\" to Windows?

How to measure time in milliseconds using ANSI C?

◇◆丶佛笑我妖孽 提交于 2019-11-26 01:37:32
问题 Using only ANSI C, is there any way to measure time with milliseconds precision or more? I was browsing time.h but I only found second precision functions. 回答1: There is no ANSI C function that provides better than 1 second time resolution but the POSIX function gettimeofday provides microsecond resolution. The clock function only measures the amount of time that a process has spent executing and is not accurate on many systems. You can use this function like this: struct timeval tval_before,

Multi-character constant warnings

谁说我不能喝 提交于 2019-11-26 01:26:32
问题 Why is this a warning? I think there are many cases when is more clear to use multi-char int constants instead of \"no meaning\" numbers or instead of defining const variables with same value. When parsing wave/tiff/other file types is more clear to compare the read values with some \'EVAW\', \'data\', etc instead of their corresponding values. Sample code: int waveHeader = \'EVAW\'; Why does this give a warning? 回答1: According to the standard (§6.4.4.4/10) The value of an integer character

How to bundle a JRE with Launch4j?

最后都变了- 提交于 2019-11-26 01:14:34
问题 I have Launch4J on my computer and it\'s a great program. One of its features I\'m interested in is the ability to bundle a JRE in the general .EXE file. However, I can\'t find any documentation that describes how to go about doing this. How do I bundle a JRE with the EXE? Plus, where do I get a compact, portable JRE to run? The download links on Oracle are for the installer packages. 回答1: After some attempts i finally get a workaround to bundle the jre in my application: I package my app as

Is there a portable way to get the current username in Python?

喜欢而已 提交于 2019-11-25 23:59:54
问题 Is there a portable way to get the current user\'s username in Python (i.e., one that works under both Linux and Windows, at least). It would work like os.getuid : >>> os.getuid() 42 >>> os.getusername() \'slartibartfast\' I googled around and was surprised not to find a definitive answer (although perhaps I was just googling poorly). The pwd module provides a relatively easy way to achieve this under, say, Linux, but it is not present on Windows. Some of the search results suggested that

Why bit endianness is an issue in bitfields?

♀尐吖头ヾ 提交于 2019-11-25 23:59:02
问题 Any portable code that uses bitfields seems to distinguish between little- and big-endian platforms. See the declaration of struct iphdr in linux kernel for an example of such code. I fail to understand why bit endianness is an issue at all. As far as I understand, bitfields are purely compiler constructs, used to facilitate bit level manipulations. For instance, consider the following bitfield: struct ParsedInt { unsigned int f1:1; unsigned int f2:3; unsigned int f3:4; }; uint8_t i; struct

How do SO_REUSEADDR and SO_REUSEPORT differ?

偶尔善良 提交于 2019-11-25 22:56:00
问题 The man pages and programmer documentations for the socket options SO_REUSEADDR and SO_REUSEPORT are different for different operating systems and often highly confusing. Some operating systems don\'t even have the option SO_REUSEPORT . The WEB is full of contradicting information regarding this subject and often you can find information that is only true for one socket implementation of a specific operating system, which may not even be explicitly mentioned in the text. So how exactly is SO

Why should I not #include <bits/stdc++.h>?

帅比萌擦擦* 提交于 2019-11-25 22:51:45
问题 I posted a question with my code whose only #include directive was the following: #include <bits/stdc++.h> My teacher told me to do this, but in the comments section I was informed that I shouldn\'t. Why? 回答1: Including <bits/stdc++.h> appears to be an increasingly common thing to see on Stack Overflow, perhaps something newly added to a national curriculum in the current academic year. I imagine the advantages are vaguely given thus: You only need write one #include line You do not need to