portability

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

主宰稳场 提交于 2021-01-29 08:42:33
问题 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

Using 'const' in C, what porting trouble might that cause?

☆樱花仙子☆ 提交于 2021-01-27 06:47:30
问题 I would like to use 'const' in C interface functions to note that certain char * arguments are not modified by the function. What trouble might this cause in porting this code to various platforms? Is support of 'const' in C code pretty standard? When did this become officially in C standard? 回答1: I can't imagine const not being supported by any compilers, so porting should be a non-issue. If you were to find such a beast, you could just put #define const Somewhere in a common header file to

Does std::hash give same result for same input for different compiled builds and different machines?

杀马特。学长 韩版系。学妹 提交于 2020-07-20 08:02:35
问题 I have some random test parameters for which I need to calculate a hash to detect if I ran with same parameters. I might run the test using the same source recompiled at a different time or run on a different machine. Even so I want to detect whether the same parameters were used for the run. Does std::hash give the same result for the same input for different compiled builds and different machines? e.g. std::hash<string>{}("TestcaseParamVal0.7Param0.4"); Will this always be a unique number?

How to actually detect musl libc?

人走茶凉 提交于 2020-06-29 05:32:14
问题 The musl team claims that there is no need of a way of detecting musl libc because they only implement standard functionality and have no quirks that need detecting. Up until today, that claim may well have been true, but it is no longer true. Normal feature detection is not working because the feature is there but broken, I'd rather not probe for it because I don't want to demand root at compile time and disallow cross-compilation. The bug has been reported with minimized sample code, and

Making stdin writable in a safe and portable way

*爱你&永不变心* 提交于 2020-03-06 09:28:08
问题 I was trying to run two programs. Case 1 #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main() { int n; int k = 10; int ret_val = 0; ret_val = write (0, &k, sizeof(int)); if (-1 == ret_val) { printf ("Failed to write"); exit (EXIT_FAILURE); } scanf ("%d", &n); printf ("Integer read is %d \n", n); return 0; } Then I tried the next one. Case 2 #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int main() {

Portable way in C++ to get desktop resolution

☆樱花仙子☆ 提交于 2020-02-21 10:25:28
问题 I'm making a C++ game, and I want it to automatically get the user's desktop resolution. I've found windows-only solutions so far - is there a way/library to find the resolution on Windows/Mac/Linux? 回答1: There are several libraries helping you at getting the low-level stuff to work out. You'll probably need more stuff on those platforms anyways, so I'll list some: SFML is a C++ library abstracting much of the I/O stuff, including display management. Also supports several platforms. The

Portable way in C++ to get desktop resolution

时光怂恿深爱的人放手 提交于 2020-02-21 10:23:13
问题 I'm making a C++ game, and I want it to automatically get the user's desktop resolution. I've found windows-only solutions so far - is there a way/library to find the resolution on Windows/Mac/Linux? 回答1: There are several libraries helping you at getting the low-level stuff to work out. You'll probably need more stuff on those platforms anyways, so I'll list some: SFML is a C++ library abstracting much of the I/O stuff, including display management. Also supports several platforms. The