getopt (3) problem?

JB Christy bchristy at aix.aix.kingston.ibm.com
Thu Sep 13 01:30:24 AEST 1990


In article <1990Sep12.011152.26067 at maverick.ksu.ksu.edu> proot at ksuvax1.cis.ksu.edu (Paul T. Root) writes:
}In compiling and running some things, I have found that getopt doesn't act
}right. When it runs out of parameters instead of returning an EOF it returns
}a -1. 
}[...]
}The work around I use is like this:
}	while(( c = getopt( argc, argv, "d:m" )), c != EOF && c != -1 ) {

I was bitten by something similar, and I believe the problem is that EOF is
#define'd as -1, which is an int, and I bet you've declared c as char.  When
the comparison occurs, c is promoted to an int but the sign is lost, so it
becomes 255 instead of -1.  Try casting EOF to a char, e.g.

	while(( c = getopt( argc, argv, "d:m" )) != (char) EOF ) {

That way -1 gets "demoted" to a char and all is well.
=-=-=-=-=
Disclaimer:  I don't even work for IBM; I certainly don't speak for them.
-- 
JB  (bchristy at aix, x0563, 5NC-01)
Resource One, Inc.			"She was a suicide blonde - dyed by
(Sub-contractor at IBM Kingston)	 her own hand."    --Rita Mae Brown



More information about the Comp.unix.aix mailing list