[C-prog-lang-l] Notes from today's lecture + a few comments

Jan Pechanec jp at devnull.cz
Tue Apr 25 12:28:34 CEST 2017


Hi folks,

today's notes and code:

http://mff.devnull.cz/c-prog-lang/notes/10--Apr-25/

I think it went very well today, you start looking like real C
programmers!

I noticed a great improvement on the C style.  A few comments on that:

	- use empty lines to separate logical sections.  For example,
	  always use an empty line after the declaration section, like
	  this:

	int i
	char c;
	<empty line>
	printf("%d\n", i);

	- never use more than one empty line

	- when initializing a structure, use one line per
	  initializator:

	struct foo {
		int i;
		char str[128];
	};

	struct foo myfoo = {
		{ 0, "hello" },
		{ 99, "hi" },
		...
	}

	- use 8 character tab for indentation.  Not two characters,
	  not 4.  8 is what the real C code uses.  Trust me :-)

- if you do not use it yet, I strongly recommend to start using some
  source code management tool to store your (any) code in.  It's worth
  to keep what you wrote for future reference.  Do not use centralized
  tools (subversion, cvs, ...), those were designed for the last
  century.  Use git or mercurial, those are distributed (or any other
  distributed SCM tool).  You could put you repo to your home
  directory on a Linux lab machine and it will be accessible from
  anywhere via SSH.  Example:

  	pechanec at u-pl3:~$ hg init my-src
  	pechanec at u-pl3:~$ exit

	jpechane:janp::~$ hg clone ssh://pechanec@u-pl3.ms.mff.cuni.cz/my-src
	destination directory: my-src
	no changes found
	updating to branch default
	0 files updated, 0 files merged, 0 files removed, 0 files unresolved
	jpechane:janp::~$
	jpechane:janp::~$ cd my-src/
	jpechane:janp::~/my-src$ mkdir test
	jpechane:janp::~/my-src$ cd test
	jpechane:janp::~/my-src/test$ vim main.c
	jpechane:janp::~/my-src/test$ hg add main.c 
	jpechane:janp::~/my-src/test$ hg commit
	jpechane:janp::~/my-src/test$ hg push
	pushing to ssh://pechanec@u-pl3.ms.mff.cuni.cz/my-src
	Password: 
	searching for changes
	remote: adding changesets                                                       
	remote: adding manifests
	remote: adding file changes
	remote: added 1 changesets with 1 changes to 1 files

J.

-- 
Jan Pechanec <jp (at) devnull (dot) cz>
http://www.devnull.cz


More information about the c-prog-lang-l mailing list