Passing by reference in C
Because you’re passing the value of the pointer to the method and then dereferencing it to get the integer that is pointed to.
Because you’re passing the value of the pointer to the method and then dereferencing it to get the integer that is pointed to.
Make (or rather a Makefile) is a buildsystem – it drives the compiler and other build tools to build your code. CMake is a generator of buildsystems. It can produce Makefiles, it can produce Ninja build files, it can produce KDEvelop or Xcode projects, it can produce Visual Studio solutions. From the same starting point, … 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
strcpy(ptr2, ptr1) is equivalent to while(*ptr2++ = *ptr1++) where as strdup is equivalent to (memcpy version might be more efficient) So if you want the string which you have copied to be used in another function (as it is created in heap section) you can use strdup, else strcpy is enough.
This is actually a fairly interesting question. It’s not as simple as it looks at first. For reference, I’m going to be basing this off of the latest C11 language grammar defined in N1570 I guess the counter-intuitive part of the question is: if this is correct C: then why is this not also correct C? … Read more
In C, using a previously undeclared function constitutes an implicit declaration of the function. In an implicit declaration, the return type is int if I recall correctly. Now, GCC has built-in definitions for some standard functions. If an implicit declaration does not match the built-in definition, you get this warning. To fix the problem, you have to … Read more
Since C++11, you can copy arrays directly with std::array: Here is the documentation about std::array
wait(NULL) will block parent process until any of its children has finished. If child terminates before parent process reaches wait(NULL) then the child process turns to a zombie process until its parent waits on it and its released from memory. If parent process doesn’t wait for its child, and parent finishes first, then the child process becomes orphan and is … Read more
Well I threw together a test program that ran each of these methods 100,000 times, half on files that existed and half on files that didn’t. Results for total time to run the 100,000 calls averaged over 5 runs, Method Time exists_test0 (ifstream) 0.485s exists_test1 (FILE fopen) 0.302s exists_test2 (posix access()) 0.202s exists_test3 (posix stat()) 0.134s The stat() function provided the … Read more
I wrote this function to read a line from a file: The function reads the file correctly, and using printf I see that the constLine string did get read correctly as well. However, if I use the function e.g. like this: printf outputs gibberish. Why?