Skip to main content
added 370 characters in body
Source Link
miracle173
  • 1.3k
  • 6
  • 19
  • Comments: comments are useful, especially if the program should be reviewed: e.g. a short description of the functions.

  • Names: meaningful names for function and variables would be useful , too.

  • System Calls: For the system calls like malloc or write you should check if it was successful. The simplest way of process an error is to write an error message and exit the program. That is better than ignoring errors and continuing processing as you do. Maybe system calls that return resources like close and free must not be checked. You can use macros that return the filename and the line number to include filename and line number inthese error messages

  • Error Messages:

  • stderr: In Unix/Linux error messages should be to stderr and not to stdin. stdin is intended for data.

  • System Error Message: the function char *strerror(int errnum); can be used to get the error message. return this error text to the user

  • Return Codes don't return always 1 in case of an error. If you have an error resulting from a system call, return it's error number. If you have other errors then return different error numbers for different errors.

  • goto: the goto should be avoided. You can use break to exit a loop. But in C the following is prefered:

while ((i = read(scll, buf, 1024)<1){
  ...
}
  • lint: Check the warnings created by the compiler. You can use lint to check your code. Here is a version accessible over the web.
  • Comments: comments are useful, especially if the program should be reviewed: e.g. a short description of the functions.

  • Names: meaningful names for function and variables would be useful , too.

  • System Calls: For the system calls like malloc or write you should check if it was successful. The simplest way of process an error is to write an error message and exit the program. That is better than ignoring errors and continuing processing as you do. Maybe system calls that return resources like close and free must not be checked. You can use macros that return the filename and the line number to include filename and line number inthese error messages

  • Error Messages:

  • stderr: In Unix/Linux error messages should be to stderr and not to stdin. stdin is intended for data.

  • System Error Message: the function char *strerror(int errnum); can be used to get the error message. return this error text to the user

  • Return Codes don't return always 1 in case of an error. If you have an error resulting from a system call, return it's error number. If you have other errors then return different error numbers for different errors.

  • goto: the goto should be avoided. You can use break to exit a loop. But in C the following is prefered:

while ((i = read(scll, buf, 1024)<1){
  ...
}
  • Comments: comments are useful, especially if the program should be reviewed: e.g. a short description of the functions.

  • Names: meaningful names for function and variables would be useful , too.

  • System Calls: For the system calls like malloc or write you should check if it was successful. The simplest way of process an error is to write an error message and exit the program. That is better than ignoring errors and continuing processing as you do. Maybe system calls that return resources like close and free must not be checked. You can use macros that return the filename and the line number to include filename and line number inthese error messages

  • Error Messages:

  • stderr: In Unix/Linux error messages should be to stderr and not to stdin. stdin is intended for data.

  • System Error Message: the function char *strerror(int errnum); can be used to get the error message. return this error text to the user

  • Return Codes don't return always 1 in case of an error. If you have an error resulting from a system call, return it's error number. If you have other errors then return different error numbers for different errors.

  • goto: the goto should be avoided. You can use break to exit a loop. But in C the following is prefered:

while ((i = read(scll, buf, 1024)<1){
  ...
}
  • lint: Check the warnings created by the compiler. You can use lint to check your code. Here is a version accessible over the web.
Source Link
miracle173
  • 1.3k
  • 6
  • 19

  • Comments: comments are useful, especially if the program should be reviewed: e.g. a short description of the functions.

  • Names: meaningful names for function and variables would be useful , too.

  • System Calls: For the system calls like malloc or write you should check if it was successful. The simplest way of process an error is to write an error message and exit the program. That is better than ignoring errors and continuing processing as you do. Maybe system calls that return resources like close and free must not be checked. You can use macros that return the filename and the line number to include filename and line number inthese error messages

  • Error Messages:

  • stderr: In Unix/Linux error messages should be to stderr and not to stdin. stdin is intended for data.

  • System Error Message: the function char *strerror(int errnum); can be used to get the error message. return this error text to the user

  • Return Codes don't return always 1 in case of an error. If you have an error resulting from a system call, return it's error number. If you have other errors then return different error numbers for different errors.

  • goto: the goto should be avoided. You can use break to exit a loop. But in C the following is prefered:

while ((i = read(scll, buf, 1024)<1){
  ...
}