Portable way to check if directory exists [Windows/Linux, C]
stat() works on Linux., UNIX and Windows as well:
stat() works on Linux., UNIX and Windows as well:
Short story: The 0 tells the parser it’s dealing with a constant (and not an identifier/reserved word). Something is still needed to specify the number base: the x is an arbitrary choice. Long story: In the 60’s, the prevalent programming number systems were decimal and octal — mainframes had 12, 24 or 36 bits per byte, which is nicely divisible by 3 = … Read more
Let’s forget the math and try to solve this intuitively. First, if we want to map input numbers in the range [0, x] to output range [0, y], we just need to scale by an appropriate amount. 0 goes to 0, x goes to y, and a number t will go to (y/x)*t. So, let’s reduce your problem to the above simpler problem. … Read more
Excerpt from http://www.mingw.org/wiki/FAQ: What’s the difference between make and mingw32-make? The “native” (i.e.: MSVCRT dependent) port of make is lacking in some functionality and has modified functionality due to the lack of POSIX on Win32. There also exists a version of make in the MSYS distribution that is dependent on the MSYS runtime. This port operates … Read more
wait returning >= 0 tells you a child process has terminated (and that calling wait didn’t fail), but it does not tell you whether that process terminated successfully or not (or if it was signalled). But, here, looking at your code, it’s fairly obvious the program does care about whether the child process that terminated did so successfully or not: … Read more
I can use pointers, but I am a bit afraid of using them. If you need a dynamic array, you can’t escape pointers. Why are you afraid though? They won’t bite (as long as you’re careful, that is). There’s no built-in dynamic array in C, you’ll just have to write one yourself. In C++, you … Read more
All CUDA API functions return an error code (or cudaSuccess if no error occured). All other parameters are passed by reference. However, in plain C you cannot have references, that’s why you have to pass an address of the variable that you want the return information to be stored. Since you are returning a pointer, … Read more
In C, a “stream” is an abstraction; from the program’s perspective it is simply a producer (input stream) or consumer (output stream) of bytes. It can correspond to a file on disk, to a pipe, to your terminal, or to some other device such as a printer or tty. The FILE type contains information about the stream. … Read more
You can pass in a pointer to a time_t object that time will fill up with the current time (and the return value is the same one that you pointed to). If you pass in NULL, it just ignores it and merely returns a new time_t object that represents the current time.
I am playing around with using Semaphores, but I keep encountering Undefined Reference warnings, thus causing my code not to work. I pulled example code from a text, but was having issues with some of their syntax, so I went to POSIX’s semaphore tutorial and changed things around to their syntax and as a result … Read more