Skip site navigation (1)Skip section navigation (2)
Date:      21 Jul 2001 17:36:59 +0200
From:      Dag-Erling Smorgrav <des@ofug.org>
To:        Damien Tougas <damien@carroll.com>
Cc:        chat@FreeBSD.ORG
Subject:   Re: C newbie needs help with kqueue
Message-ID:  <xzp3d7quwdg.fsf@flood.ping.uio.no>
In-Reply-To: <2042320000.995728574@sprig.tougas.net>
References:  <2042320000.995728574@sprig.tougas.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Damien Tougas <damien@carroll.com> writes:
> #include <stdio.h>
> #include <unistd.h>
> #include <sys/types.h>
> #include <sys/event.h>
> #include <sys/time.h>

Wrong header ordering; <sys/types.h> always comes first, followed by
other sys headers in alphabetical order, followed by standard headers
in alphabetical order.

> int main(int argc, char *argv[]) {

int
main(int argc, char *argv[])
{

>         if ((fp = fopen("/var/log/messages", "r")) == NULL) {
>                 perror("Cannot open file\n");
>                 return -1;

Don't use perror(3).  Never return from main(), use exit(3) instead
(err(3) in this case) to flag it as an exit point.  Valid exit codes
are 0-255 only.

>                 }

Incorrect brace placement.

>         if (kq = kqueue() < 0) {
>                 perror("Cannot create kqueue");
>                 }

If you were using the right compiler options (i.e. at least -Wall),
the compiler would warn you that the < operator has higher precedence
than the = operator.

DES
-- 
Dag-Erling Smorgrav - des@ofug.org

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-chat" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?xzp3d7quwdg.fsf>