GNU Coding Guidelines Shakthi Kannan GNU Free Documentation License October 2007 Version 1.0
How to use the GPL /* * main.c * * The main file of the program * Copyright (C) 2007 Shakthi Kannan <shakthi.kannan@qvantel.com> * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */
Clean-up temporary files. Check $TMPDIR. Else use /tmp. Clean-up temporary files.
Error messages Interactive programs Non-interactive programs program : message program : source-file-name : lineno : message program : source-file-name : lineno : column : message Interactive programs source-file-name: lineno-1-lineno-2: message source-file-name: lineno-1.column-1-column-2: message source-file-name: lineno-1.column-1-lineno-2.column-2: message
Comments /* So, you can comment? */ /* * You can pass more comments?
Naming Use lowercase only for variables. int pencil; Separate names with underscore: int return_my_pencil; Use all CAPS for constants. #define JAMES_BOND 007
Functions Check return values. Example: malloc () system calls
Function declaration void add_to_list (char *buf, char *rbuf); char *gamma (char *buf); int run_test (struct gnc *x);
C function parentheses /* the main function */ int main (int argc, char *argv[]) { }
Long function arguments void select_team (char *players, int advertising, int eleven) { /* do nothing */ }
if-else constructs if (you_sleep) { printf (“Good”); } else printf (“You're awake!”);
do-while constructs do { /* speak the truth */ } while (true);
Splitting long expressions split before operator if (bored_life && dull_friends && remaining_conditions) { /* cheer up! */ }
Internationalization Use GNU gettext file.c printf (_(“%s, never take life seriously. Nobody gets out alive, anyway\n” your_name); file.pot msgid “%s, never take life seriously. Nobody gets out alive, anyway\n” msgstr “”
ChangeLog 2006-02-07 Matthew Allum <mallum@openedhand.com> * applets/mb-applet-system-monitor.c: (system_memory), (main): * configure.ac: Detect kernel version at run rather than build time. 2006-01-27 Matthew Allum <mallum@openedhand.com> * src/msg.c: (_get_server_time), (msg_win_create), (msg_handle_events), (msg_calc_win_size): * src/panel.c: (panel_main): * src/session.c: (session_preexisting_clear_current): * src/session.h: Apply patch from Phil Blundell remove uneeded polling. ( See bug #68 )
README README ===== Greetings! The directory contains simple Linux device driver code examples, for character device operations. The device drivers are for 2.6 kernels. The code examples include: ex1-hello-world/ ex2-init-exit/ ex3-doc-license/ ex4-param/ ex5-multi-file/ ex6-char-register/ ex7-char-dev-register/ ex8-char-dev-register-dynamic/ ex9-write/ ex10-read/ ex11-debug/ ex12-proc/ ex13-ioctl
References Richard Stallman. September 23, 2007. GNU Coding Standards. http://www.gnu.org/prep/standards/ Gary V. Vaughan, Ben Elliston, Tom Tromey, and Ian Lance Taylor. February 8, 2006. GNU Autoconf, Automake, and Libtool. http://sources.redhat.com/autobook/