Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Monday, March 10, 2008

Big decimal integer constant warning


warning: this decimal constant is unsigned only in ISO C90

if there is no suffix added to the constant:

C90 compilers will follow the following order to read that constant:
  • int
  • long int
  • unsigned long int
while C99 compilers the following order:
  • signed int
  • signed long
  • signed long long
solution:
  1. consult compiler (gcc) documentation
  2. add proper suffix (ex. UL)
code snippet:


if((u64)s[i-1]>4294967295UL) {
s[i-1]=0;
}

Thursday, March 6, 2008

Printk ()

Links::

Example::
printk( KERN_ERR "Failed to register device %s with major %d\n", MOD_NAME, MAJOR);

It is possible to read and modify the console loglevel using the text file
/proc/sys/kernel/printk.

The file hosts four integer values:
  • current loglevel,
  • default level for messages that lack an explicit loglevel,
  • minimum allowed loglevel
  • the boot-time default loglevel.
Writing a single value to this file changes the current loglevel to that value; thus, for example, you can cause all kernel messages to appear at the console by simply entering:



# echo 8 > /proc/sys/kernel/printk


KERN_* parameters are defined in

include/linux/kernel.h
as follows:



Macro NameNumeric Value
Description
KERN_EMERG0Used for emergency messages, usually those that precede a crash.

KERN_ALERT1A situation requiring immediate action.

KERN_CRIT2Critical conditions, often related to serious hardware or software failures.

KERN_ERR3Used to report error conditions; device drivers often use KERN_ERR to report hardware difficulties.

KERN_WARNING4Warnings about problematic situations that do not, in themselves, create serious problems with the system.

KERN_NOTICE5Situations that are normal, but still worthy of note. A number of security-related conditions are reported at this level.

KERN_INFO6Informational messages. Many drivers print information about the hardware they find at startup time at this level.

KERN_DEBUG7Used for debugging messages.

Tuesday, March 4, 2008

All C/C++ manpages

apt-get install manpages
apt-get install manpages-dev
apt-get install manpages-posix-dev