theducks: (Default)
[personal profile] theducks
Dear LazyGDB..

Not knowing much about C, I find myself confused by the following, extrapolated from some code I didn't write:

Code:
#include <stdlib.h>
#include <signal.h>

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

        char    opt;
        char    *options = "a:de:f:l:p:";

        opt = getopt(argc, argv, options);
        printf ("Opt: %d\n",opt);

}


Linux on PowerPC:
suffix:~# ./test -a fish
Opt: 97
suffix:~# ./test
Opt: 255


Linux on i686:
vitalstatistix:~# ./test -a fish
Opt: 97
vitalstatistix:~# ./test 
Opt: -1


What is the deal?

(no subject)

Date: 2008-08-05 04:54 am (UTC)
From: [identity profile] theducks.livejournal.com
See, that's what I would have thought.. but in the code I was looking at, it was indeed a char..

(no subject)

Date: 2008-08-05 11:18 am (UTC)
From: [identity profile] zharradan.livejournal.com
premature optimisation root of evil etc

ISO 9899 section J3.4

Date: 2008-08-05 07:57 pm (UTC)
From: [identity profile] mkj.livejournal.com
char's signedness is implementation-defined. If you care, use "(un)signed char" or pass some gcc flag to force it a particular way.

J3.4
"Which of signed char or unsigned char has the same range, representation, and behavior as ‘‘plain’’ char"

April 2023

S M T W T F S
      1
2345678
91011121314 15
16171819202122
23242526272829
30      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 7th, 2025 10:29 pm
Powered by Dreamwidth Studios