ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi all, hope someone can help me out with this problem. I've written some code which works fine. However I get an warning which I'm unsure how to correct.
Basically I have an array of structures (actually screen set up structures) which I turn off from a kill screen function. However the code produces the following warning
LibaryFilesVer006/SetUpScreen.c: In function ‘killGLWindow’:
LibaryFilesVer006/SetUpScreen.c:170: warning: value computed is not used
LibaryFilesVer006/SetUpScreen.c: In function ‘InitScreenWindows’:
LibaryFilesVer006/SetUpScreen.c:315: warning: value computed is not used
These are called when I step through the array of pointers for each screen connect to my PC so for example the error on line 170 is from the line#
if ((*screenlist)->ctx)
{
if (!glXMakeCurrent(DisplayPointer, None, NULL))
{
printf("Could not release drawing context.\n");
}
glXDestroyContext(DisplayPointer, (*screenlist)->ctx);
(*screenlist)->ctx = NULL;
}
/* switch back to original desktop resolution if we were in fs */
if ((*screenlist)->fs)
{
XF86VidModeSwitchToMode(DisplayPointer, (*screenlist)->screen, &(*screenlist)->deskMode);
XF86VidModeSetViewPort(DisplayPointer, (*screenlist)->screen, 0, 0);
}
**screenlist++;
}
XCloseDisplay(DisplayPointer);
}
Can someone tell me how to get rid of this warning? Thanks
LibaryFilesVer006/SetUpScreen.c:315: warning: value computed is not used
**screenlist++;
The compiler already told you pretty exactly what is wrong.
You are incrementing screenlist, which is also what you probably want to do here, but additionally, you dereference screenlist. Twice. Without using the value you get from dereferencing. Why?
has two problems (well, three as far as the standard is concerned since omitting the return value of main is not valid).
First, the order of the evaluation of the function arguments is undefined. This is true for both C and C++.
Second, and this is the more sinister problem, the code evaulates argv *and* modifies it for a purpose other than generating a new value without an intervening sequence point. This is undefined behaviour.
I was sure about the argument evaluation order but I was unsure about the sequence point error, so I forwarded this question to a group which is known for having several gurus. This is their reply in a nutshell.
First, the order of the evaluation of the function arguments is undefined. This is true for both C and C++.
OK you are correct.
Quote:
Second, and this is the more sinister problem, the code evaulates argv *and* modifies it for a purpose other than generating a new value without an intervening sequence point. This is undefined behaviour.
nonsense
in the c-faq
Quote:
If you want to break rule 1, make sure that the several objects being modified are distinctly different, and try to limit yourself to two or at most three modifications, and of a style matching those of the following examples. (Also, make sure that you continue to follow rule 2 for each object modified.) The expression
c = *p++
is allowed under this rule, because the two objects modified (c and p) are distinct. The expression
*p++ = c
is also allowed, because p and *p (i.e. p itself and what it points to) are both modified but are almost certainly distinct.
Last edited by bigearsbilly; 08-28-2007 at 03:31 AM.
No, you are talking nonsense. The problem is not *argv++ by itself but that you also have *argv. There is no intervening sequence point here, hence undefined behaviour. Here's the relevant part from the comp.lang.c FAQ: http://www.c-faq.com/expr/evalorder1.html
The folks at comp.lang.c agreed totally that this is undefined behaviour, it wasn't even a discussion and I think comp.lang.c is the best place to go if one has questions regarding standard C. No other forum beats the level of expertise exhibited by its regulars. Same goes for comp.lang.c++ when it comes to c++. When one has platform specific questions, like posix, this forum good, however.
agreed,
I was saying there is nothing wrong with *argv++,
you seemed to me to be implying *argv++ is undefined,
I agree with the point is an issue only because of the
function argument evaluation order.
which is the only issue by point of fact.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.