473,382 Members | 1,809 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

To void parameter 'argc' is never used

What should I do to avoid the message :
parameter 'argc' is never used

My program is down :
*--------------------
/* Book name : The prodessional programmers guide to C
File name : E:\programs\bc\witi01\ch10\main.c
Program discription: TV rental system menu driven-ver01-W
*/

#include <stdio.h>

main(int argc,char *argv[])
{
int option;
do
{
display_menu();
option=user_selection();
if (option!=7) /*Exit*/
call_program(option,argv);
} while (option!=7);

}

display_menu()
{
system("cls");
printf ("\n TV Rental system");
printf ("\n ----------------");
printf("\n\n 1 Set up new customer");
printf("\n\n 2 Change existing customer record");
printf("\n\n 3 Add new customer record");
printf("\n\n 4 Delete customer record");
printf("\n\n 5 Print customer bills");
printf("\n\n 6 display a customer record");
printf("\n\n 7 Exit");
}
user_selection()
{
int opt;
printf("\n Enter required option(1-7) : ");
/*scanf("\n");*/
scanf("%d",&opt);
return (opt);
}

call_program(int opt,char *argv[])
{
switch(opt)
{
case 1:
/*module OK 1 Set up new customer*/
spawnvp(0,"tvfsup2.exe",argv);
delay();
break;
case 2:
/*module OK 2 Change existing customer record*/
spawnvp(0,"tvfalt2.exe",argv);
delay();
break;
case 3:
/*module OK 3 Add new customer record*/
spawnvp(0,"tvfadd2.exe",argv);
delay();
break;
case 4:
/*module OK 4 Delete customer record*/
spawnvp(0,"tvfdel2.exe",argv);
delay();
break;
case 5:
/*module OK 5 Print customer bills*/
spawnvp(0,"tv19.exe",argv);
delay();
break;
case 6:
/*module OK 6 display a customer record*/
spawnvp(0,"tvfrec2.exe",argv);
delay();
break;

default:
printf("\n incoreect input");
delay();
exit(0);
}
}

delay()
{
double i;
for (i=0;i<31000;i=i+0.5);
}
Nov 14 '05 #1
19 9510
It's a warning saying that you are not using argc; this is not problematic,
the compiler is just saying; hey you defined this function with a parameter
but you don't use that parameter within the scope of that function.

If it really bothers you, you can add:

argc = argc ;

in main().

Question for the group, why was argc included anyway (what is the history
behind it) - given that NULL == argv[argc] (i.e. it's terminated anway) ?

Cheers,
Gibby
"hp******@yahoo.com" <eh***********@yahoo.com> wrote in message
news:7e**************************@posting.google.c om...
What should I do to avoid the message :
parameter 'argc' is never used

My program is down :
*--------------------
/* Book name : The prodessional programmers guide to C
File name : E:\programs\bc\witi01\ch10\main.c
Program discription: TV rental system menu driven-ver01-W
*/

#include <stdio.h>

main(int argc,char *argv[])
{
int option;
do
{
display_menu();
option=user_selection();
if (option!=7) /*Exit*/
call_program(option,argv);
} while (option!=7);

}

display_menu()
{
system("cls");
printf ("\n TV Rental system");
printf ("\n ----------------");
printf("\n\n 1 Set up new customer");
printf("\n\n 2 Change existing customer record");
printf("\n\n 3 Add new customer record");
printf("\n\n 4 Delete customer record");
printf("\n\n 5 Print customer bills");
printf("\n\n 6 display a customer record");
printf("\n\n 7 Exit");
}
user_selection()
{
int opt;
printf("\n Enter required option(1-7) : ");
/*scanf("\n");*/
scanf("%d",&opt);
return (opt);
}

call_program(int opt,char *argv[])
{
switch(opt)
{
case 1:
/*module OK 1 Set up new customer*/
spawnvp(0,"tvfsup2.exe",argv);
delay();
break;
case 2:
/*module OK 2 Change existing customer record*/
spawnvp(0,"tvfalt2.exe",argv);
delay();
break;
case 3:
/*module OK 3 Add new customer record*/
spawnvp(0,"tvfadd2.exe",argv);
delay();
break;
case 4:
/*module OK 4 Delete customer record*/
spawnvp(0,"tvfdel2.exe",argv);
delay();
break;
case 5:
/*module OK 5 Print customer bills*/
spawnvp(0,"tv19.exe",argv);
delay();
break;
case 6:
/*module OK 6 display a customer record*/
spawnvp(0,"tvfrec2.exe",argv);
delay();
break;

default:
printf("\n incoreect input");
delay();
exit(0);
}
}

delay()
{
double i;
for (i=0;i<31000;i=i+0.5);
}

Nov 14 '05 #2
In article <news:40***********************@news.wanadoo.nl>
Gibby Koldenhof <flux@__*********@nebule.com> writes:
Question for the group, why was argc included anyway (what is the history
behind it) - given that NULL == argv[argc] (i.e. it's terminated anway) ?


In particularly ancient, long-pre-standard Unix systems (probably
mid-1970s), argv[argc] either did not exist or was -1 (I am not
sure which). I believe the decision to make argv[argc] exist and
be NULL occurred when environments were added to the Unix exec()
system call (which became execve() rather than execv()).

Only the startup code that called main() for you had to change
to implement the new feature, and it could now count up the argv
elements while searching for the first "envp" pointer and pass
argc to main() to maintain backwards compatibility.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #3

"hp******@yahoo.com" <eh***********@yahoo.com> wrote in message news:7e**************************@posting.google.c om...
What should I do to avoid the message :
parameter 'argc' is never used

My program is down :
*--------------------
/* Book name : The prodessional programmers guide to C
File name : E:\programs\bc\witi01\ch10\main.c
Program discription: TV rental system menu driven-ver01-W
*/

[..]

F:\Vijay\C> type main.c
#include <stdlib.h>

#ifdef __FLAG /* enable from command line */

/* Avoid warning: `ident' defined but not used */
#ifdef __GNUC__
#define UNUSED __attribute__ (( unused ))

/* Turbo C/C++ specific */
#elif defined(__TCPLUSPLUS__) || defined(__MSDOS__)
#define UNUSED
#pragma warn -var

#else

#define UNUSED
#endif

#else

#define UNUSED
#endif /* __FLAG */

int
main ( int argc UNUSED, char *argv[] UNUSED )
{
int a;
return EXIT_SUCCESS;
}

F:\Vijay\C> gcc main.c -Wall -W
unused.c: In function `main':
unused.c:27: warning: unused variable `a'
unused.c:25: warning: unused parameter `argc'
unused.c:25: warning: unused parameter `argv'

F:\Vijay\C> gcc main.c -Wall -W -D__FLAG
unused.c: In function `main':
unused.c:27: warning: unused variable `a'

F:\Vijay\C> bcc32 main.c -wuse
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
unused.c:
Warning W8057 unused.c 29: Parameter 'argc' is never used in function main
Warning W8057 unused.c 29: Parameter 'argv' is never used in function main
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland

--
Vijay Kumar R Zanvar
My Home Page - http://www.geocities.com/vijoeyz/
Nov 14 '05 #4
"hp******@yahoo.com" wrote:

What should I do to avoid the message :
parameter 'argc' is never used

My program is down :
*--------------------
/* Book name : The prodessional programmers guide to C
File name : E:\programs\bc\witi01\ch10\main.c
Program discription: TV rental system menu driven-ver01-W
*/

#include <stdio.h>

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

Why do you have argc and argv in main() if you aren't using them? Just
change the signature to:
int main(void)

Brian Rodenborn
Nov 14 '05 #5
In <c8*********@news1.newsguy.com> Chris Torek <no****@torek.net> writes:
In article <news:40***********************@news.wanadoo.nl>
Gibby Koldenhof <flux@__*********@nebule.com> writes:
Question for the group, why was argc included anyway (what is the history
behind it) - given that NULL == argv[argc] (i.e. it's terminated anway) ?


In particularly ancient, long-pre-standard Unix systems (probably
mid-1970s), argv[argc] either did not exist or was -1 (I am not
sure which).


K&R1 doesn't mention argv[argc] at all. argv[argc - 1] is the last
element with a defined meaning. When K&R2 introduced argv[argc], it used
the words "; additionally, the standard requires that argv[argc] be a null
pointer".

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #6
In <7e**************************@posting.google.com > eh***********@yahoo.com (hp******@yahoo.com) writes:
What should I do to avoid the message :
parameter 'argc' is never used


Remove the compiler option that checks for unused function arguments:
IMHO it's a cure worse than the disease.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #7
In <40***********************@news.wanadoo.nl> "Gibby Koldenhof" <flux@__*********@nebule.com> writes:
Question for the group, why was argc included anyway (what is the history
behind it) - given that NULL == argv[argc] (i.e. it's terminated anway) ?


Isn't it obvious? argv[] hasn't always been a null pointer terminated
array.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #8
In <2h************@uni-berlin.de> "Vijay Kumar R Zanvar" <vi*****@globaledgesoft.com> writes:

F:\Vijay\C> type main.c
#include <stdlib.h>

#ifdef __FLAG /* enable from command line */

/* Avoid warning: `ident' defined but not used */
#ifdef __GNUC__
#define UNUSED __attribute__ (( unused ))

/* Turbo C/C++ specific */
#elif defined(__TCPLUSPLUS__) || defined(__MSDOS__)
#define UNUSED
#pragma warn -var

#else

#define UNUSED
#endif

#else

#define UNUSED
#endif /* __FLAG */

int
main ( int argc UNUSED, char *argv[] UNUSED )
{
int a;
return EXIT_SUCCESS;
}

F:\Vijay\C> gcc main.c -Wall -W
unused.c: In function `main':
unused.c:27: warning: unused variable `a'
unused.c:25: warning: unused parameter `argc'
unused.c:25: warning: unused parameter `argv'


Using the preprocessor to bastardise the language syntax is a cure far
worse than the disease.

In the case of gcc, it's much simpler not to use -W in the first place.
If the -W warnings haven't been included in -Wall, there *must* be a
*good* reason.

fangorn:~/tmp 129> cat test.c
int main(int argc, char **argv)
{
int a;
return 0;
}
fangorn:~/tmp 130> gcc -Wall test.c
test.c: In function `main':
test.c:3: warning: unused variable `a'
fangorn:~/tmp 131>

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #9
Dan Pop wrote:
In <7e**************************@posting.google.com > eh***********@yahoo.com (hp******@yahoo.com) writes:

What should I do to avoid the message :
parameter 'argc' is never used

Remove the compiler option that checks for unused function arguments:
IMHO it's a cure worse than the disease.


This is a matter on which reasonable people can
disagree, perhaps even amicably. Such a warning can
certainly help catch typos:

double length(double x0, double y0,
double x1, double y1)
{
return hypot(x1 - x0, y1 - x0);
}

If the compiler complains about `y0' being unused, it
has done me a favor. My own preference is to accept
all such favors with gratitude, my preferred gcc options
are "-Wall -W -ansi -pedantic" (omitting the final two
when compiling some kinds of system-specific code).

A source construct that suppresses the "unused"
warning from most compilers (including the gcc versions
I've encountered) is

int main(int unused, char *argv[]) {
...
(void)unused;
...

Of course, the quest to eliminate every warning from
every compiler is ultimately futile. The compiler is
permitted to issue any warnings it feels like. Some may
complain that `(void)unused;' is a statement that doesn't
do anything -- you may simply have traded one warning
for another. That's why I suggest using a name like
`unused', so that when some compiler somewhere complains
despite your best efforts, the programmer who's tracking
down the complaint will recognize it as unimportant.

--
Er*********@sun.com

Nov 14 '05 #10
In <40**************@boeing.com.invalid> Default User <fi********@boeing.com.invalid> writes:
"hp******@yahoo.com" wrote:

What should I do to avoid the message :
parameter 'argc' is never used

My program is down :
*--------------------
/* Book name : The prodessional programmers guide to C
File name : E:\programs\bc\witi01\ch10\main.c
Program discription: TV rental system menu driven-ver01-W
*/

#include <stdio.h>

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


Why do you have argc and argv in main() if you aren't using them? Just
change the signature to:

int main(void)


There are cases when only one of main's arguments is relevant. Trivial
examples (assume <stdio.h> has been included):

int main(int argc, char **argv)
{
printf("Program invoked with %d arguments\n", argc - 1);
return 0;
}

int main(int argc, char **argv)
{
while (*argv != NULL) puts(argv++);
return 0;
}

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #11
in comp.lang.c i read:
"hp******@yahoo.com" <eh***********@yahoo.com> wrote in message
news:7e**************************@posting.google. com...
What should I do to avoid the message :
parameter 'argc' is never used


ask your compiler not to tell you about unused identifiers if they don't
matter to you.
#ifdef __FLAG /* enable from command line */
invading the reserved namespace is dicey at best.
#elif defined(__TCPLUSPLUS__) || defined(__MSDOS__)
#define UNUSED
#pragma warn -var


this disables unused variable warnings for the remainder of the program,
whereas you otherwise (appear to) provide a per-variable mechanism -- this
can lead to surprises.

--
a signature
Nov 14 '05 #12
Dan Pop wrote:

In <40**************@boeing.com.invalid> Default User <fi********@boeing.com.invalid> writes:
Why do you have argc and argv in main() if you aren't using them? Just
change the signature to:

int main(void)


There are cases when only one of main's arguments is relevant.


Tis very true. The example given was not one of those. My desire was to
get the OP thinking about all aspects of his program rather than
engaging in Cargo Cult programming. I think you'd agree that encouraging
someone to engage their brain is a worthwhile pursuit.
Trivial
examples (assume <stdio.h> has been included):


I am quite sure you aren't trying to lecture me on such usuage, but to
provide examples for others. Naturally, I'm quite familiar with most
variations on command-line programs.


Brian Rodenborn
Nov 14 '05 #13
In article <40***************@boeing.com.invalid>,
Default User <fi********@boeing.com.invalid> wrote:
Dan Pop wrote:

In <40**************@boeing.com.invalid> Default User
<fi********@boeing.com.invalid> writes:
Why do you have argc and argv in main() if you aren't using them?
Just change the signature to:

int main(void)
There are cases when only one of main's arguments is relevant.

Tis very true. The example given was not one of those. My desire was to
get the OP thinking about all aspects of his program rather than
engaging in Cargo Cult programming. I think you'd agree that encouraging
someone to engage their brain is a worthwhile pursuit.


The OP's code used argv in the line:

call_program(option,argv);

so it is not possible to remove the arguments from main.

Kevin Bagust.

Nov 14 '05 #14
On Mon, 24 May 2004 01:14:26 +0200, "Gibby Koldenhof"
<flux@__*********@nebule.com> wrote:
Question for the group, why was argc included anyway (what is the history
behind it) - given that NULL == argv[argc] (i.e. it's terminated anway) ?


As others have said, it wasn't always that way. Regardless, it's
convenient to have argc. One obvious case is checking that the number
of parameters is correct without having to look at all of them.

--
Al Balmer
Balmer Consulting
re************************@att.net
Nov 14 '05 #15
On Mon, 24 May 2004 20:35:25 +0100, in comp.lang.c , Kevin Bagust
<ke**********@ntlworld.com> wrote:
In article <40***************@boeing.com.invalid>,
Default User <fi********@boeing.com.invalid> wrote:
Dan Pop wrote:
>
> In <40**************@boeing.com.invalid> Default User
> <fi********@boeing.com.invalid> writes: > >Why do you have argc and argv in main() if you aren't using them?
> >Just change the signature to:
> >
> >int main(void)
>
> There are cases when only one of main's arguments is relevant.

Tis very true. The example given was not one of those. My desire was to


The OP's code used argv in the line:
call_program(option,argv);


Quite possibly. I humbly suggest that in that case, he actually needs to
use argc too, since it tells him something important about argv. This is of
course the easiest way to remove the warning.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 14 '05 #16
Kevin Bagust wrote:
The OP's code used argv in the line:

call_program(option,argv);

Ah, I missed that in the initial read-through.

In that case, my comments were inappropriate.


Brian Rodenborn
Nov 14 '05 #17
Da*****@cern.ch (Dan Pop) writes:
In <40***********************@news.wanadoo.nl> "Gibby Koldenhof"
<flux@__*********@nebule.com> writes:
Question for the group, why was argc included anyway (what is the history
behind it) - given that NULL == argv[argc] (i.e. it's terminated anway) ?


Isn't it obvious? argv[] hasn't always been a null pointer terminated
array.


No, it's not particularly obvious (even though it happens to be true).

--
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 14 '05 #18
Eric Sosman <Er*********@sun.com> wrote in message news:<40************@sun.com>...

A source construct that suppresses the "unused"
warning from most compilers (including the gcc versions
I've encountered) is

int main(int unused, char *argv[]) {
...
(void)unused;
...


Another that often works is

unused = unused;
Nov 14 '05 #19
In <ln************@nuthaus.mib.org> Keith Thompson <ks***@mib.org> writes:
Da*****@cern.ch (Dan Pop) writes:
In <40***********************@news.wanadoo.nl> "Gibby Koldenhof"
<flux@__*********@nebule.com> writes:
>Question for the group, why was argc included anyway (what is the history
>behind it) - given that NULL == argv[argc] (i.e. it's terminated anway) ?


Isn't it obvious? argv[] hasn't always been a null pointer terminated
array.


No, it's not particularly obvious (even though it happens to be true).


The presence of argc is a very strong clue that argv doesn't need a
sentinel value. If such a value exists, nevertheless, it is very likely
that it was added later (for some reason that is not obvious to people
unfamiliar with main's nonstandard third argument), when it was too late
to remove argc.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: Marcin Vorbrodt | last post by:
Is there any reason why auto_ptr does not have the cast operator like this: operator void* (); So that one could easily test auto_ptr for NULL ??? Standard does not declare such operator. Is...
192
by: Kwan Ting | last post by:
The_Sage, I see you've gotten yourself a twin asking for program in comp.lang.c++ . http://groups.google.co.uk/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&th=45cd1b289c71c33c&rnum=1 If you the oh so mighty...
14
by: Dan | last post by:
Is it just me, or is the removal of support for the word "void" in a parameter list extremely annoying? Some of us have been programming for years putting "void function_name (void)" - and it...
1
by: cirederf | last post by:
Hello, I am trying to run a code which compiles fine, but when I try to run it I am facing a series of problems which are quite difficult to understand. I am kind of new with C, the task is then...
6
by: rahulsinner | last post by:
Hello everyone, I have noticed everyone using "int main(void)".But doesnt the standard pronounces it as "int main(int argc,char *argv)".And if i don't specify arguments,why can't i simply put...
27
by: Erik de Castro Lopo | last post by:
Hi all, The GNU C compiler allows a void pointer to be incremented and the behaviour is equivalent to incrementing a char pointer. Is this legal C99 or is this a GNU C extention? Thanks in...
7
by: bwaichu | last post by:
In some APIs, we see char ** or void ** as a parameter. I never distinguished between declaring a variable as char **x and passing x as the parameter from declaring a variable char *x and passing...
18
by: hyderabadblues | last post by:
What does (void) poService in followinf peace of code mean tclCtrlBoard::tclCtrlBoard( void* poService ) { # if defined Something (void) poService; \\ What does this mean }
16
by: PeterAPIIT | last post by:
Hello all C++ expert programmer, i have wrote partial general allocator for my container. After reading standard C++ library and code guru article, i have several questions. 1. Why...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.