I am confused about the code snippet given below.
int main(int argc, char** argv)
{
AA( main )
USENOT( argc );
USENOT( argv );
exit( 0 );
return;
}
whereas AA is defined as any one of the following based on some
condition
#define AA(a) ar[i++] = #a;
or
#define AA(a) printf(#a "\n");
or
#define AA(a) ;
ar is defined as
extern char *ar[];
USENOT is defined as
#define USENOT(x) (x=x)
1.Can somebody explain what's happening after entering the function
main in all the three cases of the values of AA.
2. what may be the USENOT's purpose. 17 1290 m_*******@yahoo.com (PranjalMishra) wrote in
news:9b**************************@posting.google.c om: I am confused about the code snippet given below.
int main(int argc, char** argv) { AA( main )
USENOT( argc ); USENOT( argv );
exit( 0 );
return; }
whereas AA is defined as any one of the following based on some condition
#define AA(a) ar[i++] = #a; or #define AA(a) printf(#a "\n"); or #define AA(a) ;
ar is defined as extern char *ar[];
USENOT is defined as #define USENOT(x) (x=x)
1.Can somebody explain what's happening after entering the function main in all the three cases of the values of AA.
Just run the program yourself compiled the 3 different ways.
2. what may be the USENOT's purpose.
To quiet the compiler warning about argc and argv not being used. The
author might better have defined main() as int main(void) in this case.
--
- Mark ->
--
PranjalMishra wrote: I am confused about the code snippet given below.
int main(int argc, char** argv) { AA( main )
USENOT( argc ); USENOT( argv );
exit( 0 );
return; }
whereas AA is defined as any one of the following based on some condition
#define AA(a) ar[i++] = #a; or #define AA(a) printf(#a "\n"); or #define AA(a) ;
ar is defined as extern char *ar[];
USENOT is defined as #define USENOT(x) (x=x)
1.Can somebody explain what's happening after entering the function main in all the three cases of the values of AA.
2. what may be the USENOT's purpose.
The snippet is basically giving you a function trace. In the first
instance, it is saving the name of the function in an array of strings.
You can then traverse that array at will. If:
#define AA(a) ar[i++] = #a;
AA(main)
the precompiler will expand the AA macro, replacing "a", (and #a is a
"stringized" version of the parameter) sending this to the compiler:
ar[i++] = "main";
This will not compile if the variable 'i' is not also defined, of course.
So the second should now be obvious:
#define AA(a) printf(#a "\n");
AA(main)
the precompiler will send:
printf("main" "\n");
And, the third case will simply eat the parameter, since the macro is empty:
#define AA(a)
AA(main)
will send:
(nothing)
I expect USENOT is a placeholder for a macro that has not yet been
defined, since it really does nothing useful.
David Logan
David Logan <dj******@comcast.net> wrote in
news:7ehAc.62224$0y.33444@attbi_s03: USENOT is defined as #define USENOT(x) (x=x)
I expect USENOT is a placeholder for a macro that has not yet been defined, since it really does nothing useful.
No, it quiets compiler warnings about unused vars.
--
- Mark ->
--
Mark A. Odell wrote: David Logan <dj******@comcast.net> wrote in news:7ehAc.62224$0y.33444@attbi_s03:
USENOT is defined as #define USENOT(x) (x=x)
I expect USENOT is a placeholder for a macro that has not yet been defined, since it really does nothing useful.
No, it quiets compiler warnings about unused vars.
I saw your post on that. I would never have thought of that. I would
have expected a more logical explanation :)
David Logan
In article <Xn********************************@130.133.1.4> ,
Mark A. Odell <od*******@hotmail.com> wrote: #define USENOT(x) (x=x)
No, it quiets compiler warnings about unused vars.
Or maybe it generates compiler warnings about pointless assignments.
-- Richard ri*****@cogsci.ed.ac.uk (Richard Tobin) wrote in
news:ca***********@pc-news.cogsci.ed.ac.uk: #define USENOT(x) (x=x)
No, it quiets compiler warnings about unused vars.
Or maybe it generates compiler warnings about pointless assignments.
I didn't say it was a good implementation of the macro :-). The RTOS I use
has a static variable that it assigns the unused parameter to. Their macro
is better named too:
/* Some RTOS header file
*/
extern unsigned long rtos_unused_parameter;
#define UNUSED_PARAMETER(x) rtos_unused_parameter = (unsigned long) (x)
--
- Mark ->
--
On 17 Jun 2004 13:58:26 GMT, "Mark A. Odell" <od*******@hotmail.com>
wrote: David Logan <dj******@comcast.net> wrote in news:7ehAc.62224$0y.33444@attbi_s03:
USENOT is defined as #define USENOT(x) (x=x)
I expect USENOT is a placeholder for a macro that has not yet been defined, since it really does nothing useful.
No, it quiets compiler warnings about unused vars.
Odd - it doesn't seem to work with my compiler.
--
Al Balmer
Balmer Consulting re************************@att.net
In <cHhAc.127046$Ly.9657@attbi_s01> David Logan <dj******@comcast.net> writes: Mark A. Odell wrote: David Logan <dj******@comcast.net> wrote in news:7ehAc.62224$0y.33444@attbi_s03:
USENOT is defined as #define USENOT(x) (x=x)
I expect USENOT is a placeholder for a macro that has not yet been defined, since it really does nothing useful.
No, it quiets compiler warnings about unused vars.
I saw your post on that. I would never have thought of that. I would have expected a more logical explanation :)
It's logical enough. Consider the following program:
#include <stdio.h>
int main(int argc, char **argv)
{
while (*argv != NULL) puts(*argv++);
return 0;
}
Some compilers/lints will warn that argc is declared but never used.
You have to choose between using the option that shuts up the warning
(or not using the option that enables it) and doing some dummy operation
with argc. If you opt for the latter approach, hiding the otherwise
meaningless argc = argc behind a macro usually named NOTUSED, renders
your intent more obvious to the human reader, as well as getting rid of
the unwanted warning.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Alan Balmer <al******@att.net> wrote in
news:cb********************************@4ax.com: USENOT is defined as #define USENOT(x) (x=x)
I expect USENOT is a placeholder for a macro that has not yet been defined, since it really does nothing useful.
No, it quiets compiler warnings about unused vars.
Odd - it doesn't seem to work with my compiler.
I believe it was intended to.
--
- Mark ->
--
In <cb********************************@4ax.com> Alan Balmer <al******@att.net> writes: On 17 Jun 2004 13:58:26 GMT, "Mark A. Odell" <od*******@hotmail.com> wrote:
David Logan <dj******@comcast.net> wrote in news:7ehAc.62224$0y.33444@attbi_s03:
USENOT is defined as #define USENOT(x) (x=x)
I expect USENOT is a placeholder for a macro that has not yet been defined, since it really does nothing useful.
No, it quiets compiler warnings about unused vars. Odd - it doesn't seem to work with my compiler.
It works for the very popular gcc -Wall -W invocation (and probably for
many others).
Of course, when it comes to compiler warnings, a program construct that
shuts up one undesired warning on one compiler may have no effect on
another compiler or even trigger another undesired warning.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
On Thu, 17 Jun 2004 06:12:06 -0700, PranjalMishra wrote: I am confused about the code snippet given below.
int main(int argc, char** argv) { AA( main )
USENOT( argc ); USENOT( argv );
exit( 0 );
return; }
whereas AA is defined as any one of the following based on some condition
Lets see what we get running it through a preprocessor: #define AA(a) ar[i++] = #a;
int main(int argc, char** argv)
{
ar[i++] = "main";
(argc=argc);
(argv=argv);
exit( 0 );
return;
}
or #define AA(a) printf(#a "\n");
int main(int argc, char** argv)
{
printf("main" "\n");
(argc=argc);
(argv=argv);
exit( 0 );
return;
}
or #define AA(a) ;
int main(int argc, char** argv)
{
;
(argc=argc);
(argv=argv);
exit( 0 );
return;
}
David Logan <dj******@comcast.net> wrote: Mark A. Odell wrote: David Logan <dj******@comcast.net> wrote in news:7ehAc.62224$0y.33444@attbi_s03:
USENOT is defined as #define USENOT(x) (x=x)
I expect USENOT is a placeholder for a macro that has not yet been defined, since it really does nothing useful.
No, it quiets compiler warnings about unused vars.
I saw your post on that. I would never have thought of that. I would have expected a more logical explanation :)
Not very 'portable', of course; on some compilers it would merely
replace the "unused variable" warning with "statement has no effect".
In 'comp.lang.c', m_*******@yahoo.com (PranjalMishra) wrote: I am confused about the code snippet given below.
int main(int argc, char** argv) { AA( main )
USENOT( argc ); USENOT( argv );
exit( 0 );
return; }
whereas AA is defined as any one of the following based on some condition
#define AA(a) ar[i++] = #a;
Debug mode: means "put the address of the string made from the parameter in
some array of pointers to char, and increment some index" (seems to have no
bound check. Bad coding.). Sounds like a trace device for interrupt code...
Note : In a macro definition, '#' changes the parameter of a macro to a
string literal
or #define AA(a) printf(#a "\n");
Debug mode: Explicitely sends a line to stdout with the name given as
parameter.
or #define AA(a) ;
Release mode: Do nothing.
Note AA is a very bad name (however, not worst than FOO or BAR)
ar is defined as extern char *ar[];
As I guessed... 'i' should be a global too... which is a VERY bad name for a
global.
Hint: globals are shadowed by locals with the same name...
USENOT is defined as #define USENOT(x) (x=x)
A twisted way of writing:
#define USENOT(x) (void)(x)
Or directly
(void)(x);
into the source code.
It's a way to mute the compiler about the 'variable or parameter defined but
not used' warning.
IMO, this warning is useful and should not be muted in debug mode. (Hence,
after all, the macro appears to be useful...)
--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
"Mark A. Odell" wrote: Alan Balmer <al******@att.net> wrote in news:cb********************************@4ax.com:
> USENOT is defined as > #define USENOT(x) (x=x)
I expect USENOT is a placeholder for a macro that has not yet been defined, since it really does nothing useful.
No, it quiets compiler warnings about unused vars. Odd - it doesn't seem to work with my compiler.
I believe it was intended to.
-- - Mark -> --
To quiet the compiler about unused arguments, I use the /* ARGSUSED */
comment immediately before the function definition. Seems to quiet most
compilers:
/* ARGSUSED */
int main( int argc, char** argv) {
....
}
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94 (206)544-5225
"Fred L. Kleinschmidt" <fred.l.kleinschmidt@nospam_boeing.com> wrote in
news:40D2FB3B.A392F289@nospam_boeing.com: To quiet the compiler about unused arguments, I use the /* ARGSUSED */ comment immediately before the function definition. Seems to quiet most compilers: /* ARGSUSED */ int main( int argc, char** argv) { ... }
How many compilers does this comment work with? It's not part of the ISO C
spec. so it's not portable.
--
- Mark ->
--
On Fri, 18 Jun 2004, Mark A. Odell wrote: "Fred L. Kleinschmidt" <fred.l.kleinschmidt@nospam_boeing.com> wrote: To quiet the compiler about unused arguments, I use the /* ARGSUSED */ comment immediately before the function definition. Seems to quiet most compilers: /* ARGSUSED */ int main( int argc, char** argv) { ... }
How many compilers does this comment work with? It's not part of the ISO C spec. so it's not portable.
It doesn't work with gcc (but I guess you knew that). As to
portability, it's a lot more sensible than the (argc=argc) version,
since at least it won't generate *extra* warnings or code if it's
not recognized. Since the Standard doesn't mention warnings for unused
arguments, obviously there is no "portable" way to quiet compiler
warnings. (*Any* compiler warnings, pedantically speaking.)
Of course, the best approach (assuming you can't or won't ignore
or disable the spurious warning by other means) is a hybrid of Fred's
and the usual method:
/* Quiet compiler warning about unused arguments */
(void)argc;
(void)argv;
-Arthur
"Fred L. Kleinschmidt" <fred.l.kleinschmidt@nospam_boeing.com> wrote in message news:<40D2FB3B.A392F289@nospam_boeing.com>... To quiet the compiler about unused arguments, I use the /* ARGSUSED */ comment immediately before the function definition. Seems to quiet most compilers: /* ARGSUSED */ int main( int argc, char** argv) { ... }
ARGSUED is historical. It was used to tell lint(1) to shut up. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: PHPkemon |
last post by:
Hi there,
A few weeks ago I made a post and got an answer which seemed very logical.
Here's part of the post:
PHPkemon wrote:
> I think I've figured out how to do the main things like...
|
by: d.warnermurray |
last post by:
I am doing a project for school that involves creating help files for a html
authoring tool.
If you could help me with answers to some questions it would really help.
1. What tasks do you expect...
|
by: Mark Reed |
last post by:
Hi all,
I am trying to learn a little about programming (I know next to nothing
so far) and have found some code which hides the toolbars. However, this bit
of code is a little too effective and...
|
by: dixie |
last post by:
Help, I'm really out of my depth here (not unusual I hear you say :-). I
have just installed HTML Help in an application. I told it in the Project
Properties the path to the help file. I then...
|
by: Timothy Shih |
last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I
wrote a simple function which takes in 2 buffers (one a byte buffer, one a
char buffer) and copies the contents of the byte...
| |
by: Jason |
last post by:
Hi,
I was wondering if any could point me to an example or give me ideas on how
to dynamically create a form based on a database table? So, I would have a
table designed to tell my application...
|
by: Allen |
last post by:
I have a class that returns an arraylist. How do I fill a list box from what
is returned? It returns customers which is a arraylist but I cant seem to
get the stuff to fill a list box. I just...
|
by: inkexit |
last post by:
I need help figuring out what is wrong with my code. I posted here a
few weeks ago with some code about creating self similar melodies in
music. The coding style I'm being taught is apparently a...
|
by: glenn123 |
last post by:
Hi, i am just about out of time to produce a working jukebox which has to perform these functions: to play music files when a track is chosen from a list which when the user presses the change genre...
|
by: JonathanOrlev |
last post by:
Hello everybody,
I wrote this comment in another message of mine, but decided to post it
again as a standalone message.
I think that Microsoft's Office 2003 help system is horrible, probably...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |