4 ms·
RMS recently released reference manual for GNU C - I am finding it to be direct and succinct. Edit: I used to teach C to a group of undergrads and one question
by blinkingled 4y ago
RMS recently released reference manual for GNU C - I am finding it to be direct and succinct.
Edit: I used to teach C to a group of undergrads and one question that came up often was around the special significance of the main function and order of definition of functions.
The RMS book addresses this very succinctly -
Every C program is started by running the function named main. Therefore, the example program defines a function named main to provide a way to start it. Whatever that function does is what the program does. The main function is the first one called when the program runs, but it doesn’t come first in the example code. The order of the function definitions in the source code makes no difference to the program’s meaning.
https://lists.gnu.org/archive/html/info-gnu/2022-09/msg00005.html https://lists.gnu.org/archive/html/info-gnu/2022-09/msg00005...
If you understand basic concepts of programming but know nothing about C, you can read this manual sequentially from the beginning to learn the C language.
- jalino23 4y agothank you for this!
- synergy20 4y agoWould be nicer if RMS can add TOC on the PDF, to make navigation _much_ easier.
- deleted 4y ago[deleted]
- curious16 4y agoCan anyone link me to the pdf directly. I don't find it on the link above. I am stupid.
- Snarwin 4y agoSomeone has uploaded a PDF to github, here: https://github.com/VernonGrant/gnu-c-language-manual https://github.com/VernonGrant/gnu-c-language-manual
- 6581 4y agoThere is no PDF.
- veqq 4y agoThere is no pdf. Following the chain, you get to a git you can download. But this guy has a tar of it as a single html page. https://forums.linuxmint.com/viewtopic.php?t=381284 https://forums.linuxmint.com/viewtopic.php?t=381284
- treeblah 4y agoThere's no direct PDF, you have to build it yourself w/ TeX by cloning the repo: git clone https://git.savannah.gnu.org/git/c-intro-and-ref.git cd c-intro-and-ref/ make c.pdf
- 1vuio0pswjnm7 4y agoI am stupid, too. I generally do not use git(1). I wrote a short script to download the manual as a single 639K text file. I do not use a GUI or mouse so this makes it easier for me to work with code snippets. I also reformat the text to match personal preferences. Here is an example script using popular curl program to make the HTTP requests. # requirements: curl, links, perl, texinfo (Linux), texi2html (BSD) #!/bin/sh set -v; x0=c-intro-and-ref.git; x1=https://git.savannah.nongnu.org/cgit/; test -d $x0||mkdir $x0;cd $x0||exit; for x2 in Makefile c.texi cpp.texi fdl.texi fp.texi texinfo.tex;do echo url=$x1$x0/plain/$x2; echo output=$x2; echo user-agent=\"\"; done|curl -K/dev/stdin -s; case $(uname) in :) ;;*BSD) texi2html --no-headers --no-split --html c.texi ;;Linux) makeinfo --no-headers --no-split --html c.texi esac; # personal preference for ~15-inch screen: 4 space indent, 60-70 max chars per line links -width 70 -dump .html \ |sed '/^ *Link:/d;/^ *\*/s/\*//;s/^/ /;/Jump to: /{N;N;d;}' > c.txt; exec less c.txt;
- tolciho 4y agoprintf 'the form\n' \ | tr a-z A-Z golfs to printf 'the form\n' | tr a-z A-Z but that only saves like one or two keystrokes but is probably good to know for shell trivia questions or when implementing something that supposedly can handle shell continuation lines
- 1vuio0pswjnm7 4y agodjb used this style when shell scripting and I believe that is where I picked it up.^1 I have not seen (m)any HN commenters publishing their work for public scrutiny who are more skilled in programming, including C, than djb. Other programmers, good ones, but not a large number, copied his C style. 1. An extreme example https://raw.githubusercontent.com/drudru/qhasm/master/qhasm-amd64 https://raw.githubusercontent.com/drudru/qhasm/master/qhasm-...
- WalterBright 4y ago> The order of the function definitions in the source code makes no difference to the program’s meaning. Not exactly true. Consider: #include <stdio.h> int foo(double d) { return (int)d; } int main() { printf("%d\n", foo(3)); return 0; } /*int foo(double d) { return (int)d; }*/ This prints different results depending on whether `foo` is defined before `main` or after `main`. This is caused by implicit function declaration. gcc will warn about this if the -std=c11 switch is thrown, but by default it will compile without error or warning.
- WalterBright 4y agoAmusingly, the ImportC compiler I wrote will produce the same result regardless of the order, because it allows forward references.
- marcodiego 4y agoHere gcc (9.4.0) throws a warning if the first declaration is commented and the second one uncommented, but it prints "0". Care to explain why?
- WalterBright 4y agoBecause foo() gets implicitly declared as accepting int arguments, when it actually accepts a double. The double bits interpreted as an int are 0.
- edflsafoiewq 4y agoOn x64, foo(double) expects its argument in xmm0, but foo(int) expects it in rdi. So the 3 passed in rdi is ignored and it operates on whatever happened to be in xmm0.
- WalterBright 4y agoYes, you're right. Thanks for the correction. I was thinking of the Windows C ABI.
- xphos 4y agoYou know I can think of a handful of examples where main is not true. C to my understanding does not define that the implementation does and think this is kind of exactly what the other is saying that this implied assumptions lead to issues in C development. This albeit is an extremely superficial assumption that isn't in 99% of cases going to matter except in of course security and embedded systems I think the biggest issue with C is that it's taught as the programs you are building is foundation of everything while brushing under the rug that in also all course work you are not build C on bare metal you almost always are building on on OS which runs an implemented hardware which are extremely important. But by teaching your building on this all powerful language makes overconfident programmers. I've known so many developers who jump the gun and think they are write what will happen on the computer without understanding how high in the clouds they normally are.