如何#define一个main()函数并调用我们自己的main函数? [英] how #define a main() function and call our own main function?
问题描述
各位大家好,
我正在编写一个小应用程序,在用户开始执行之前做了一些工作
主函数开始执行。
我正在尝试#define主要功能。
但问题是,
用户的main()函数可能属于不同类型
1. main()
2.main(int argc)
3. main(int argc,char * argv [])
如何#define所有这三种可能性。并且没有
保证用户将始终使用相同的名称argc& argv
。我们还需要知道argments名称,如果需要访问
他们。
我正在尝试这样做。
#define main(a,b)main(a,b){
my_function();
user_main(argc,argv);
}
user_main(a,b)
但如果我们必须处理上面列出的3个案例,这将不起作用。
和还有agrument名称问题。
我能就此提出一些建议吗?
提前致谢。
-
Ravi.T
9月24日晚上10点03分,ravi< gototh ... @ gmail.comwrote:
大家好,
我正在写一个小应用程序在用户之前做了一些工作
主要功能开始执行。
我正在尝试#define主要功能。
但问题是,用户的main()函数可能是
不同类型
1. main()
2.main(int argc)
#2是严格不允许使用该语言。
3. main(int argc,char * argv [])
如何#define所有这三种可能性。并且没有
保证用户将始终使用相同的名称argc& argv
。我们还需要知道argments名称,如果需要访问
他们。
我正在尝试这样做。
#define main(a,b)main(a,b){
my_function();
user_main(argc,argv);
}
user_main(a,b)
但如果我们必须处理上面列出的3个案例,这将不起作用。
和还有agrument名称问题。
我能就此提出一些建议吗?
你只需要这个:
int main(int argc,char ** argv);
如果没有参数,那么argc将为零或1.
9月25日上午10点29分, user923005< dcor ... @ connx.comwrote:
9月24日晚上10点03分,ravi< gototh ... @ gmail.comwrote:
大家好,
我正在编写一个小应用程序,它在用户
主函数开始执行。
我正在尝试#define主函数。
但问题是,
main()用户的功能可能是不同的类型
1. main()
2.main(int argc)
$ b语言严格禁止$ b#2。
3. main(int argc,char * argv [])
< blockquote class =post_quotes>
如何#define所有这三种可能性。并且没有
保证用户将始终使用相同的名称argc& argv
。如果需要访问
,我们还需要知道argments名称。
我正在尝试这样做。
#define main(a,b)main(a,b){
my_function();
user_main(argc,argv);
}
user_main(a,b)
但如果我们必须处理上面列出的3个案例,这将无效。
以及agrument名称问题。
我可以就此提出一些建议吗?
你只需要这个:
int main(int argc,char ** argv);
如果没有参数,那么argc将为零或1.
你能不能试试这个程序:
example.c:
int main(int argc)
{
printf(Hello World \ n);
返回0;
}
我可以编译并运行它。
9月24日晚上10点49分,ravi< gototh ... @ gmail.comwrote:
9月25日,10:29 am,user923005< dcor ... @ connx.comwrote:
9月24日晚上10点03分,ravi<得到了... @ gmail.comwrote:
大家好,
我写的一个小应用程序,它在用户之前完成一些工作
主函数开始执行。
我正在尝试#define主函数。
但问题是,
用户的main()函数可能是不同类型的
1. main()
2.main(int argc)
语言严格禁止
#2。
3. main(int argc,char * argv [])
如何#define所有这三种可能性。并且没有
保证用户将始终使用相同的名称argc& argv
。如果需要访问
,我们还需要知道argments名称。
我正在尝试这样做。
#define main (a,b)main(a,b){
my_function();
user_main(argc,argv);
}
user_main(a,b)
但是这不起作用我们必须处理上面列出的3个案例。
以及agrument名称问题。
我可以就此提出一些建议吗?
你只需要这个:
int main(int argc,char ** argv);
如果没有参数,那么argc将为零或1.
你可以试试这个程序:
example.c:
int main(int argc)
{
printf(Hello World \ n);
返回0;}
我能够编译并运行这个
这很有趣。它让恶魔飞出我的鼻子。我想我应该
注意我的错误检查器:
C:\ tmp>夹板tc
Splint 3.1 .1 --- 2007年3月12日
tc(1,17):函数main用1 arg声明,应该有2(int argc,
char
* argv [])
函数main与预期类型不匹配。 (使用-maintype
禁止
警告)
tc :(在函数main中)
tc(1 ,26):未使用参数argc
函数体中未使用函数参数。如果类型兼容性或未来计划需要
参数
,请使用/ * @ unused @ * /
参数声明。 (使用-paramuse禁止警告)
完成检查--- 2个代码警告
C:\ tmp> type tc
int main(int argc)
{
printf(Hello World \ n);
返回0;
}
C:\ tmp> lin tc
C:\ tmp>" ; C:\Lint\Lint-NT" + v -i" C:\ Lint" std.lnt -os(_LINT.TMP)t.c
PC-lint for C / C ++(NT)Vers。 8.00u,版权所有Gimpel Software
1985-2006
---模块:tc(C)
C:\ tmp>输入_LINT.TMP |更多
---模块:tc(C)
_
printf(Hello World \ n) ;
tc(3):信息718:符号''printf''未声明,假设返回int
tc(3):信息746:调用函数'' printf()''没有在
中出现
原型
_
}
tc(6):信息715:符号''argc''(第1行)未引用
tc(1):信息830:先前消息中引用的位置
_
}
tc(6):注952:参数''argc''(第1行)可以声明为const
--- Eff。
C ++ 3rd Ed。第3项
tc(1):信息830:先前消息中引用的位置
---全球总结
警告526:符号''printf()''(第3行,文件tc)未定义
tc(3):信息830:先前消息中引用的位置
警告628:没有为功能提供参数信息
''printf()''(第3行,
文件tc)
tc(3):信息830:先前消息中引用的位置
---
输出放在_LINT.TMP
Hello everybody,
I am writing a small application which does some work before the user
main function starts execution.
I am trying to #define the main function.
But the problem is that,
the main () function by user may be of different types
1. main()
2.main(int argc)
3. main(int argc, char *argv[])
How to #define all these three possibilities. And there is not
guarantee that the user is going to use the same names "argc &argv"
all the times. we need also know the argments name if needed to access
them.
I am trying to do this.
#define main(a,b) main(a,b){
my_function();
user_main(argc,argv);
}
user_main(a,b)
But this will not work if we have to deal with above listed 3 cases.
and also the agrument names problem.
Can I have some suggestions on this?
Thanks in advance.
--
Ravi.T
On Sep 24, 10:03 pm, ravi <gototh...@gmail.comwrote:Hello everybody,
I am writing a small application which does some work before the user
main function starts execution.
I am trying to #define the main function.
But the problem is that,
the main () function by user may be of different types
1. main()
2.main(int argc)#2 is strictly not allowed by the language.
3. main(int argc, char *argv[])
How to #define all these three possibilities. And there is not
guarantee that the user is going to use the same names "argc &argv"
all the times. we need also know the argments name if needed to access
them.
I am trying to do this.
#define main(a,b) main(a,b){
my_function();
user_main(argc,argv);
}
user_main(a,b)
But this will not work if we have to deal with above listed 3 cases.
and also the agrument names problem.
Can I have some suggestions on this?You only need this one:
int main(int argc, char **argv);
If there are no arguments, then argc will be zero or 1.
On Sep 25, 10:29 am, user923005 <dcor...@connx.comwrote:On Sep 24, 10:03 pm, ravi <gototh...@gmail.comwrote:
Hello everybody,
I am writing a small application which does some work before the user
main function starts execution.
I am trying to #define the main function.
But the problem is that,
the main () function by user may be of different types
1. main()
2.main(int argc)
#2 is strictly not allowed by the language.
3. main(int argc, char *argv[])
How to #define all these three possibilities. And there is not
guarantee that the user is going to use the same names "argc &argv"
all the times. we need also know the argments name if needed to access
them.
I am trying to do this.
#define main(a,b) main(a,b){
my_function();
user_main(argc,argv);
}
user_main(a,b)
But this will not work if we have to deal with above listed 3 cases.
and also the agrument names problem.
Can I have some suggestions on this?
You only need this one:
int main(int argc, char **argv);
If there are no arguments, then argc will be zero or 1.Can you please try this program:
example.c:
int main(int argc)
{
printf("Hello World\n");
return 0;
}
I am able to compile and run this.
On Sep 24, 10:49 pm, ravi <gototh...@gmail.comwrote:On Sep 25, 10:29 am, user923005 <dcor...@connx.comwrote:
On Sep 24, 10:03 pm, ravi <gototh...@gmail.comwrote:
Hello everybody,
I am writing a small application which does some work before the user
main function starts execution.
I am trying to #define the main function.
But the problem is that,
the main () function by user may be of different types
1. main()
2.main(int argc)
#2 is strictly not allowed by the language.
3. main(int argc, char *argv[])
How to #define all these three possibilities. And there is not
guarantee that the user is going to use the same names "argc &argv"
all the times. we need also know the argments name if needed to access
them.
I am trying to do this.
#define main(a,b) main(a,b){
my_function();
user_main(argc,argv);
}
user_main(a,b)
But this will not work if we have to deal with above listed 3 cases.
and also the agrument names problem.
Can I have some suggestions on this?
You only need this one:
int main(int argc, char **argv);
If there are no arguments, then argc will be zero or 1.
Can you please try this program:
example.c:
int main(int argc)
{
printf("Hello World\n");
return 0;}
I am able to compile and run thisThat''s funny. It made demons fly out of my nose. I guess I should
have paid attention to my error checkers:
C:\tmp>splint t.c
Splint 3.1.1 --- 12 Mar 2007
t.c(1,17): Function main declared with 1 arg, should have 2 (int argc,
char
*argv[])
The function main does not match the expected type. (Use -maintype
to inhibit
warning)
t.c: (in function main)
t.c(1,26): Parameter argc not used
A function parameter is not used in the body of the function. If the
argument
is needed for type compatibility or future plans, use /*@unused@*/
in the
argument declaration. (Use -paramuse to inhibit warning)
Finished checking --- 2 code warnings
C:\tmp>type t.c
int main(int argc)
{
printf("Hello World\n");
return 0;
}
C:\tmp>lin t.c
C:\tmp>"C:\Lint\Lint-nt" +v -i"C:\Lint" std.lnt -os(_LINT.TMP) t.c
PC-lint for C/C++ (NT) Vers. 8.00u, Copyright Gimpel Software
1985-2006
--- Module: t.c (C)
C:\tmp>type _LINT.TMP | more
--- Module: t.c (C)
_
printf("Hello World\n");
t.c(3) : Info 718: Symbol ''printf'' undeclared, assumed to return int
t.c(3) : Info 746: call to function ''printf()'' not made in the
presence of a
prototype
_
}
t.c(6) : Info 715: Symbol ''argc'' (line 1) not referenced
t.c(1) : Info 830: Location cited in prior message
_
}
t.c(6) : Note 952: Parameter ''argc'' (line 1) could be declared const
--- Eff.
C++ 3rd Ed. item 3
t.c(1) : Info 830: Location cited in prior message
--- Global Wrap-up
Warning 526: Symbol ''printf()'' (line 3, file t.c) not defined
t.c(3) : Info 830: Location cited in prior message
Warning 628: no argument information provided for function
''printf()'' (line 3,
file t.c)
t.c(3) : Info 830: Location cited in prior message
---
output placed in _LINT.TMP
这篇关于如何#define一个main()函数并调用我们自己的main函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!