By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,433 Members | 1,702 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,433 IT Pros & Developers. It's quick & easy.

getopt()

P: n/a
What is the correct format of getopt() and how does it work? I looked
at the man page; it doesn't really clarify things. What's a program
that uses it, maybe I could figure it out from that.

Note: This is on-topic. getopt is part of the standard library.

Andrew Usher

Nov 15 '05 #1
Share this Question
Share on Google+
18 Replies


P: n/a

[fups set to c.p]

On Sun, 5 Nov 2005 k_**********@yahoo.com wrote:

What is the correct format of getopt() and how does it work? I looked
at the man page; it doesn't really clarify things. What's a program
that uses it, maybe I could figure it out from that.
man 3 getopt
(is not the same as)
man getopt
Note: This is on-topic. getopt is part of the standard library.


Note: getopt is certainly *NOT* part of the standard library; I don't
know where you got that idea. Questions such as yours which are not
related to ISO standard C should be directed to a group where they'd be
on-topic, such as comp.programming, one of the gnu. hierarchy, or perhaps
a Linux programming group.

-Arthur
Nov 15 '05 #2

P: n/a
k_**********@yahoo.com writes:
getopt is part of the standard library.


No it isn't.
--
"...deficient support can be a virtue.
It keeps the amateurs off."
--Bjarne Stroustrup
Nov 15 '05 #3

P: n/a
Ben Pfaff wrote:
k_**********@yahoo.com writes:
getopt is part of the standard library.


No it isn't.


??? It is in libc. Maybe it's Unix-specific, but C is Unix.

Andrew Usher

Nov 15 '05 #4

P: n/a
k_**********@yahoo.com writes:
Ben Pfaff wrote:
k_**********@yahoo.com writes:
> getopt is part of the standard library.


No it isn't.


??? It is in libc. Maybe it's Unix-specific, but C is Unix.


libc is not the standard C library (i.e., the library defined by the C
language standard).

C is a language; Unix is an operating system. C is not Unix; Unix is
not C.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #5

P: n/a
Keith Thompson wrote:
??? It is in libc. Maybe it's Unix-specific, but C is Unix.
libc is not the standard C library (i.e., the library defined by the C
language standard).


That library doesn't exist! The only C is the one people actually use.
I don't care for bureaucratic s*** here more than anywhere else.
C is a language; Unix is an operating system. C is not Unix; Unix is
not C.


I know that, obviously. But C is written for Unix and vice versa.

Andrew Usher

P.S. As far as getopt(), I wrote some test programs and I think I have
figured it out. It doesn't really work well with a ':' other than at
the end, though. I think anyone who's serious about processing command
lines would write his own modification.

Nov 15 '05 #6

P: n/a
k_**********@yahoo.com writes:
Keith Thompson wrote:
> ??? It is in libc. Maybe it's Unix-specific, but C is Unix.


libc is not the standard C library (i.e., the library defined by the C
language standard).


That library doesn't exist! The only C is the one people actually use.
I don't care for bureaucratic s*** here more than anywhere else.


The topic of this newsgroup is the C language as defined by the
standard (which doesn't include getopt). If you want to discuss
something else, there are other newsgroups; in comp.unix.programmer,
for example, they're far more likely to be able to answer your
questions than we are.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #7

P: n/a
k_**********@yahoo.com wrote:
but C is Unix.


So what do you call Windows3.1 then? Unix??? It certainly was written
in C as much as any variant of Unix were.

I've written on systems where their libc includes support for CANbus
and ARCnet but I recognise that they were vendor specific additions to
libc. Just because gcc has its own extended libc doesn't mean that ALL
C compilers need to emulate it to conform to C standards (ANSI, C99,
etc).

Nov 15 '05 #8

P: n/a
k_**********@yahoo.com wrote:
I don't care for bureaucratic s*** here more than anywhere else.


I think the problem with this newgroup,
is that "comp.lang.c" is too easy to spell.

http://www.csclub.uwaterloo.ca/u/dj3...lc-welcome.txt

news:comp.unix.programmer

--
pete
Nov 15 '05 #9

P: n/a
k_**********@yahoo.com wrote:
Note: This is on-topic. getopt is part of the standard library.


On what do you base this obviously false assertion?
Nov 15 '05 #10

P: n/a
k_**********@yahoo.com wrote:
Keith Thompson wrote:

??? It is in libc. Maybe it's Unix-specific, but C is Unix.


libc is not the standard C library (i.e., the library defined by the C
language standard).


That library doesn't exist! The only C is the one people actually use.
I don't care for bureaucratic s*** here more than anywhere else.


did you notice that you are the only person in this thread that thinks
that. Could it
perhaps be that you are wrong?

<snip>
--
Nick Keighley

The use of COBOL cripples the mind; its teaching should, therefore,
be regarded as a criminal offense. -E. W. Dijkstra

Nov 15 '05 #11

P: n/a
<k_**********@yahoo.com> wrote

That library doesn't exist! The only C is the one people actually use.
I don't care for bureaucratic s*** here more than anywhere else.
It is not just bureaucratese.
If write a program in ANSI C, then you can guarantee that it will compile
and run on any system with a ANSI C compiler. If it doesn't you can complain
to the compiler vendor, and he will either have to post a fix or remove the
claim to ANSI compatibility.
On the other hand if you use a non-standard function like getopt(), you may
end up having to implement it youself. There is no getopt() on my Windows C
compiler, for instance.
C is a language; Unix is an operating system. C is not Unix; Unix is
not C.


I know that, obviously. But C is written for Unix and vice versa.

They grew up together. And C works more nicely on Unix than any other
system. However only a minority of my C programs have been for Unix - most
are either Windows or games console programs.
Nov 15 '05 #12

P: n/a

"Keith Thompson" <ks***@mib.org> wrote in message
news:ln************@nuthaus.mib.org...
k_**********@yahoo.com writes:
Ben Pfaff wrote:
k_**********@yahoo.com writes:

> getopt is part of the standard library.

No it isn't.


??? It is in libc. Maybe it's Unix-specific, but C is Unix.


libc is not the standard C library (i.e., the library defined by the C
language standard).

C is a language; Unix is an operating system. C is not Unix;


Let's start the CNU movement! :-)

-Mike
Nov 15 '05 #13

P: n/a
k_**********@yahoo.com wrote:
What is the correct format of getopt() and how does it work? I looked
at the man page; it doesn't really clarify things. What's a program
that uses it, maybe I could figure it out from that. Note: This is on-topic. getopt is part of the standard library.


getopt is defined in the Standard Unix Specification, not ANSI C.
The online SUSv3 description has example usage:

http://www.opengroup.org/onlinepubs/...ns/getopt.html

And of course, there are about a gazillion Free Software programs out there
that use getopt, all with viewable, usable and redistributable source code.

Direct any questions to comp.unix.programmer.
Nov 15 '05 #14

P: n/a
On 5 Nov 2005 22:13:49 -0800, in comp.lang.c , k_**********@yahoo.com
wrote:
Ben Pfaff wrote:
k_**********@yahoo.com writes:
> getopt is part of the standard library.
No it isn't.


??? It is in libc.


So are lots of things platform-specific.
Maybe it's Unix-specific,
It may be POSIX, but you'd have to ask in a unix group to find out.
but C is Unix.


Not since about 1970. Get with the right millenium
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #15

P: n/a
On 5 Nov 2005 23:24:25 -0800, in comp.lang.c , k_**********@yahoo.com
wrote:
Keith Thompson wrote:
C is a language; Unix is an operating system. C is not Unix; Unix is
not C.


I know that, obviously. But C is written for Unix and vice versa.


Maybe once upon a time, C was targettted at an early version of unix ,
but that was 30-odd years ago. Unix certainly was never written for
C.
The first proper rockets were targetted at london, does that make the
shuttle 'for' london, and vice-versa?

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #16

P: n/a
k_**********@yahoo.com wrote:

That library doesn't exist! The only C is the one people actually use.
I don't care for bureaucratic s*** here more than anywhere else.

Annnnnnd *plonk*.

Brian
Nov 15 '05 #17

P: n/a
k_**********@yahoo.com wrote:

Keith Thompson wrote:
??? It is in libc. Maybe it's Unix-specific, but C is Unix.
libc is not the standard C library (i.e., the library defined by the C
language standard).


That library doesn't exist! The only C is the one people actually use.


Well, there's no such thing as "the one people actually use", because
there is no "the" C compiler. There are many C compilers available, and
most (if not all) include extensions to the standard. Those extensions
(of which getopt is one) are off-topic here.

There is, however, something called "the" C language, and that is what
is discussed here. (Well, there have been several revisions to "the"
language.)

And, one of the C compilers that I actually use shows:

==========
C:\temp>cl foo.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

foo.c
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/out:foo.exe
foo.obj
foo.obj : error LNK2001: unresolved external symbol _getopt
foo.exe : fatal error LNK1120: 1 unresolved externals
==========
I don't care for bureaucratic s*** here more than anywhere else.
And off-topic posts aren't welcome here more than anywhere else.

I can hear a lot of plonking going on over that sentence.
C is a language; Unix is an operating system. C is not Unix; Unix is
not C.


I know that, obviously. But C is written for Unix and vice versa.


Since when? C, as defined in the standard and discussed in this group,
doesn't even require an O/S. (It doesn't even require a keyboard and
display.)
P.S. As far as getopt(), I wrote some test programs and I think I have
figured it out. It doesn't really work well with a ':' other than at
the end, though. I think anyone who's serious about processing command
lines would write his own modification.


Or ask for help in a group where this discussion is not off-topic.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Nov 15 '05 #18

P: n/a
Mike Wahler <mk******@mkwahler.net> wrote:
Let's start the CNU movement! :-)


Or, perhaps the analagous UNC movement, but that would not be popular
with Duke fans, I'm afraid... :-)

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 15 '05 #19

This discussion thread is closed

Replies have been disabled for this discussion.