LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-09-2004, 01:31 PM   #1
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
gcc feature deprecation question


Hi, I'm using gcc-3.3.4 and I get a warning with the following code that I don't quite understand:

Code:
#include <stdio.h>

void myfunc(int *a)
{
  printf("%d\n", *a);
}

int main(void)
{
  int a = 1, b = 2;

  myfunc(&(a == 1?a:b));

  return 0;
}
The warnings I get are:
Quote:
$ gcc -Wall foo.c -o foo
foo.c: In function `main':
foo.c:12: warning: use of conditional expressions as lvalues is deprecated
foo.c:12: warning: use of compound expressions as lvalues is deprecated
If I change myfunc(&(a == 1?a:b)); to myfunc(&(1?a:b)); I don't get the warnings.

I know that the code I pasted is completely useless, but I use that conditional test to pass arguments to functions sometimes. My question is why would something like that be deprecated? I can't find anything in the announcements at http://gcc.gnu.org that say that it will be deprecated.

On another machine running gcc-3.2.3 I don't get the warnings using that same code.

Any insight would be appreciated. Thanks!
 
Old 07-09-2004, 02:10 PM   #2
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
you should be able to do

Code:
myfunc(a == 1 ? &a : &b);
to get the effect you want without warnings. To me that reads more clearly anyway. I think the idea behind the deprecation is that by the time the ?: operator is evaluated, you're left with a simple value, not a variable, and so you can't necessarily take the address of it. e.g.

Code:
myfunc(&(a == 1 ? a : 3));
doesn't look fundamentally different from your original, yet it might turn out to be &3, which makes no sense.
 
Old 07-09-2004, 02:51 PM   #3
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Original Poster
Rep: Reputation: 59
That makes sense and it does work if I try your suggestion, but it still doesn't make sense that &(1?a:b) doesn't give the message since it could still resolve to something like &(1?a:3).

But anyway, distributing the ampersand to the variables is a fine fix for me. Thanks for the help
 
Old 07-09-2004, 03:33 PM   #4
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
I'm guessing that &(1?a:b) is either a pseudo-bug or pseudo-feature. It could be that it gets optimized to &a before the part that checks for the deprecation gets to it. (In other words, the fact that the part before the ? is constant could lead gcc down a different code path.)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Password Encryption After MD5 Deprecation ombill Fedora 1 08-22-2005 05:16 PM
Feature question Cryptic_K Slackware 8 08-12-2004 12:52 PM
GCC Question SainT1337 Linux - General 2 11-30-2003 01:11 PM
Question about GCC 3.2.2 and 2.95 deepsix Programming 9 07-30-2003 02:54 AM
gcc question 0micron Linux - Software 4 02-19-2003 03:02 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration