Hacker News new | past | comments | ask | show | jobs | submit login

Part 3:

"Wait a tic... Where's the Makefile? I've got just about as much chance of finding it as the FBI does of finding Jimmy Hoffa. Am I just supposed to imagine it into existence?"

I think the point is that the make command can use implicit rules even if there is no Makefile. It knows how to compile C source files. (This could be confusing if you know about "make" but don't know about implicit rules.) For example:

    $ ls
    hello.c
    $ cat hello.c
    #include <stdio.h>
    int main(void) {
        puts("hello");
        return 0;
    }
    $ make hello
    cc     hello.c   -o hello
    $ ./hello
    hello
    $
Later: "So, I'm just supposed to poke in some code, go to my terminal, type this magic 'make' word, and expect a built and working program, right?"

Yes, that's exactly what you're supposed to do. Try it, it should work.

Part 10 mentions strncpy() as a safer strcpy(). It isn't. http://the-flat-trantor-society.blogspot.com/2012/03/no-strn...

(Disclaimer: I haven't read Zed Shaw's book, and I don't intend to.)




I'm glad you posted the article on strcpy; I did not know about this behavior of strncpy and am a little surprised I never ran into it before.

That being said; it is a safer alternative to strcpy, but it seems like it isn't the safest alternative to strcpy.


strncpy, when used as designed, can leave the target array without a terminating null character. Using that array later with any string function causes undefined behavior.

strcpy, when used as designed, always leaves the target array properly null-terminated. Using it properly is a bit more difficult; you have to make sure the target array is big enough to hold the source string.

This sequence:

    target[0] = '\0';
    strncat(target, source, sizeof target);
does what most people probably assume strncpy should do (assuming target is defined as an array rather than as a pointer).


What about strcpy_s ??


strcpy_s is not universally available.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: