public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* how to implement this ?
@ 2013-01-07 14:31 horseriver
  2013-01-07 14:53 ` Andrew Haley
  0 siblings, 1 reply; 11+ messages in thread
From: horseriver @ 2013-01-07 14:31 UTC (permalink / raw)
  To: gcc-help

hi:

  how to implement this assignment by MACRO?
  int a,b,c ;
  
  ((a==0)?b:c)=8;

  if use this sentence ,gcc will tell :error: lvalue required as left operand of assignment

  is there s implementation for this with  macro  define?

  is there suggestion ?

  
  thanks!

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: how to implement this ?
  2013-01-07 14:31 how to implement this ? horseriver
@ 2013-01-07 14:53 ` Andrew Haley
  2013-01-07 15:09   ` horseriver
  0 siblings, 1 reply; 11+ messages in thread
From: Andrew Haley @ 2013-01-07 14:53 UTC (permalink / raw)
  To: horseriver; +Cc: gcc-help

On 01/07/2013 04:46 AM, horseriver wrote:
> hi:
> 
>   how to implement this assignment by MACRO?
>   int a,b,c ;
>   
>   ((a==0)?b:c)=8;

This is for help with GCC, not general C coding help.

*((a==0) ? &b : &c) = 8;

But this is really horrible code.  I wouldn't do it.

Andrew.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: how to implement this ?
  2013-01-07 14:53 ` Andrew Haley
@ 2013-01-07 15:09   ` horseriver
  2013-01-07 15:21     ` Andrew Haley
  0 siblings, 1 reply; 11+ messages in thread
From: horseriver @ 2013-01-07 15:09 UTC (permalink / raw)
  To: Andrew Haley; +Cc: gcc-help

On Mon, Jan 07, 2013 at 02:31:19PM +0000, Andrew Haley wrote:
> On 01/07/2013 04:46 AM, horseriver wrote:
> > hi:
> > 
> >   how to implement this assignment by MACRO?
> >   int a,b,c ;
> >   
> >   ((a==0)?b:c)=8;
> 
> This is for help with GCC, not general C coding help.
> 
> *((a==0) ? &b : &c) = 8;
> 
> But this is really horrible code.  I wouldn't do it.

thans!
  
  why gcc report that error ?
  
  gcc can translate "  ((a==0)?b:c)=8 " into if-else sentence .

  wht is the reason ?
> 
> Andrew.
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: how to implement this ?
  2013-01-07 15:09   ` horseriver
@ 2013-01-07 15:21     ` Andrew Haley
  2013-01-07 15:25       ` horseriver
  0 siblings, 1 reply; 11+ messages in thread
From: Andrew Haley @ 2013-01-07 15:21 UTC (permalink / raw)
  To: horseriver; +Cc: gcc-help

On 01/07/2013 05:11 AM, horseriver wrote:
> On Mon, Jan 07, 2013 at 02:31:19PM +0000, Andrew Haley wrote:
>> On 01/07/2013 04:46 AM, horseriver wrote:
>>> hi:
>>>
>>>   how to implement this assignment by MACRO?
>>>   int a,b,c ;
>>>   
>>>   ((a==0)?b:c)=8;
>>
>> This is for help with GCC, not general C coding help.
>>
>> *((a==0) ? &b : &c) = 8;
>>
>> But this is really horrible code.  I wouldn't do it.
> 
> thans!
>   
>   why gcc report that error ?
>   
>   gcc can translate "  ((a==0)?b:c)=8 " into if-else sentence .
> 
>   wht is the reason ?

Please supply the test case and the error message.

Andrew.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: how to implement this ?
  2013-01-07 15:21     ` Andrew Haley
@ 2013-01-07 15:25       ` horseriver
  2013-01-07 15:35         ` Andrew Haley
  0 siblings, 1 reply; 11+ messages in thread
From: horseriver @ 2013-01-07 15:25 UTC (permalink / raw)
  To: Andrew Haley; +Cc: gcc-help

On Mon, Jan 07, 2013 at 03:09:31PM +0000, Andrew Haley wrote:
> On 01/07/2013 05:11 AM, horseriver wrote:
> > On Mon, Jan 07, 2013 at 02:31:19PM +0000, Andrew Haley wrote:
> >> On 01/07/2013 04:46 AM, horseriver wrote:
> >>> hi:
> >>>
> >>>   how to implement this assignment by MACRO?
> >>>   int a,b,c ;
> >>>   
> >>>   ((a==0)?b:c)=8;
> >>
> >> This is for help with GCC, not general C coding help.
> >>
> >> *((a==0) ? &b : &c) = 8;
> >>
> >> But this is really horrible code.  I wouldn't do it.
> > 
> > thans!
> >   
> >   why gcc report that error ?
> >   
> >   gcc can translate "  ((a==0)?b:c)=8 " into if-else sentence .
> > 
> >   wht is the reason ?
> 
> Please supply the test case and the error message.
> 

ok

here is this code : 

#define INPUT_KEYCODE(dev, scancode) ((dev->keycodesize == 1) ? ((u8*)dev->keycode)[scancode] : \
			((dev->keycodesize == 2) ? ((u16*)dev->keycode)[scancode] : (((u32*)dev->keycode)[scancode])))

and here is the callee code :

        unsigned int keycode ;
	
    	INPUT_KEYCODE(dev, scancode) = keycode;

        dev is a struct , scancode is a unsigned int

and gcc report error is :

        error: lvalue required as left operand of assignment

thanks!

> Andrew.
> 
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: how to implement this ?
  2013-01-07 15:25       ` horseriver
@ 2013-01-07 15:35         ` Andrew Haley
  2013-01-07 15:44           ` horseriver
  0 siblings, 1 reply; 11+ messages in thread
From: Andrew Haley @ 2013-01-07 15:35 UTC (permalink / raw)
  To: horseriver; +Cc: gcc-help

On 01/07/2013 05:39 AM, horseriver wrote:
> On Mon, Jan 07, 2013 at 03:09:31PM +0000, Andrew Haley wrote:
>> On 01/07/2013 05:11 AM, horseriver wrote:
>>> On Mon, Jan 07, 2013 at 02:31:19PM +0000, Andrew Haley wrote:
>>>> On 01/07/2013 04:46 AM, horseriver wrote:
>>>>> hi:
>>>>>
>>>>>   how to implement this assignment by MACRO?
>>>>>   int a,b,c ;
>>>>>   
>>>>>   ((a==0)?b:c)=8;
>>>>
>>>> This is for help with GCC, not general C coding help.
>>>>
>>>> *((a==0) ? &b : &c) = 8;
>>>>
>>>> But this is really horrible code.  I wouldn't do it.
>>>
>>> thans!
>>>   
>>>   why gcc report that error ?
>>>   
>>>   gcc can translate "  ((a==0)?b:c)=8 " into if-else sentence .
>>>
>>>   wht is the reason ?
>>
>> Please supply the test case and the error message.
>>
> 
> ok
> 
> here is this code : 
> 
> #define INPUT_KEYCODE(dev, scancode) ((dev->keycodesize == 1) ? ((u8*)dev->keycode)[scancode] : \
> 			((dev->keycodesize == 2) ? ((u16*)dev->keycode)[scancode] : (((u32*)dev->keycode)[scancode])))
> 
> and here is the callee code :
> 
>         unsigned int keycode ;
> 	
>     	INPUT_KEYCODE(dev, scancode) = keycode;
> 
>         dev is a struct , scancode is a unsigned int
> 
> and gcc report error is :
> 
>         error: lvalue required as left operand of assignment

That is the wrong error.

I need to see the whole of the code that resulted in the error that was
"gcc can translate "  ((a==0)?b:c)=8 " into if-else sentence ."

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: how to implement this ?
  2013-01-07 15:35         ` Andrew Haley
@ 2013-01-07 15:44           ` horseriver
  2013-01-07 15:49             ` Andrew Haley
  0 siblings, 1 reply; 11+ messages in thread
From: horseriver @ 2013-01-07 15:44 UTC (permalink / raw)
  To: Andrew Haley; +Cc: gcc-help

On Mon, Jan 07, 2013 at 03:29:59PM +0000, Andrew Haley wrote:
> On 01/07/2013 05:39 AM, horseriver wrote:
> > On Mon, Jan 07, 2013 at 03:09:31PM +0000, Andrew Haley wrote:
> >> On 01/07/2013 05:11 AM, horseriver wrote:
> >>> On Mon, Jan 07, 2013 at 02:31:19PM +0000, Andrew Haley wrote:
> >>>> On 01/07/2013 04:46 AM, horseriver wrote:
> >>>>> hi:
> >>>>>
> >>>>>   how to implement this assignment by MACRO?
> >>>>>   int a,b,c ;
> >>>>>   
> >>>>>   ((a==0)?b:c)=8;
> >>>>
> >>>> This is for help with GCC, not general C coding help.
> >>>>
> >>>> *((a==0) ? &b : &c) = 8;
> >>>>
> >>>> But this is really horrible code.  I wouldn't do it.
> >>>
> >>> thans!
> >>>   
> >>>   why gcc report that error ?
> >>>   
> >>>   gcc can translate "  ((a==0)?b:c)=8 " into if-else sentence .
> >>>
> >>>   wht is the reason ?
> >>
> >> Please supply the test case and the error message.
> >>
> > 
> > ok
> > 
> > here is this code : 
> > 
> > #define INPUT_KEYCODE(dev, scancode) ((dev->keycodesize == 1) ? ((u8*)dev->keycode)[scancode] : \
> > 			((dev->keycodesize == 2) ? ((u16*)dev->keycode)[scancode] : (((u32*)dev->keycode)[scancode])))
> > 
> > and here is the callee code :
> > 
> >         unsigned int keycode ;
> > 	
> >     	INPUT_KEYCODE(dev, scancode) = keycode;
> > 
> >         dev is a struct , scancode is a unsigned int
> > 
> > and gcc report error is :
> > 
> >         error: lvalue required as left operand of assignment
> 
> That is the wrong error.
> 
> I need to see the whole of the code that resulted in the error that was
> "gcc can translate "  ((a==0)?b:c)=8 " into if-else sentence ."

   gcc can translate "  ((a==0)?b:c)=8 " into if-else sentence   

   is my idea ,not a reported error
   
   thanks!
   > 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: how to implement this ?
  2013-01-07 15:44           ` horseriver
@ 2013-01-07 15:49             ` Andrew Haley
  2013-01-07 15:52               ` horseriver
  0 siblings, 1 reply; 11+ messages in thread
From: Andrew Haley @ 2013-01-07 15:49 UTC (permalink / raw)
  To: horseriver; +Cc: gcc-help

On 01/07/2013 05:57 AM, horseriver wrote:
>    gcc can translate "  ((a==0)?b:c)=8 " into if-else sentence   
> 
>    is my idea ,not a reported error

Oh, you mean why does C not allow ((a==0)?b:c)=8;

You'd have to ask the C standard committee.  It's not something
that the language allows.

Andrew.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: how to implement this ?
  2013-01-07 15:49             ` Andrew Haley
@ 2013-01-07 15:52               ` horseriver
  2013-01-07 17:05                 ` Andrew Haley
  0 siblings, 1 reply; 11+ messages in thread
From: horseriver @ 2013-01-07 15:52 UTC (permalink / raw)
  To: Andrew Haley; +Cc: gcc-help

On Mon, Jan 07, 2013 at 03:44:01PM +0000, Andrew Haley wrote:
> On 01/07/2013 05:57 AM, horseriver wrote:
> >    gcc can translate "  ((a==0)?b:c)=8 " into if-else sentence   
> > 
> >    is my idea ,not a reported error
> 
> Oh, you mean why does C not allow ((a==0)?b:c)=8;
> 
> You'd have to ask the C standard committee.  It's not something
> that the language allows.
but I find this use in kernel code .

code have been post in  last  mail 




> 
> Andrew.
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: how to implement this ?
  2013-01-07 15:52               ` horseriver
@ 2013-01-07 17:05                 ` Andrew Haley
  0 siblings, 0 replies; 11+ messages in thread
From: Andrew Haley @ 2013-01-07 17:05 UTC (permalink / raw)
  To: horseriver; +Cc: gcc-help

On 01/07/2013 06:07 AM, horseriver wrote:
> On Mon, Jan 07, 2013 at 03:44:01PM +0000, Andrew Haley wrote:
>> On 01/07/2013 05:57 AM, horseriver wrote:
>>>    gcc can translate "  ((a==0)?b:c)=8 " into if-else sentence   
>>>
>>>    is my idea ,not a reported error
>>
>> Oh, you mean why does C not allow ((a==0)?b:c)=8;
>>
>> You'd have to ask the C standard committee.  It's not something
>> that the language allows.
> but I find this use in kernel code .

GCC used to allow it as a language extension, a long time ago.

Andrew.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: how to implement this ?
  2013-01-07 15:30 ugiwgh
@ 2013-01-07 15:39 ` horseriver
  0 siblings, 0 replies; 11+ messages in thread
From: horseriver @ 2013-01-07 15:39 UTC (permalink / raw)
  To: ugiwgh; +Cc: gcc-help

On Mon, Jan 07, 2013 at 11:25:10PM +0800, ugiwgh wrote:
> If I didn't understand wrong, you can do it like this.
> 
> #define calc(_a,_b,_c) ((0==(_a))?((_b)==8):((_c)=8))
> 

actually,I want use ((a==0)?b:c) to select a variable name ,which can be used as left value also as right value.


thanks!

	


gcc-help <gcc-help@gcc.gnu.org>
> 
> 
> ------------------ Original ------------------
> From:  "horseriver"<horserivers@gmail.com>;
> Date:  Mon, Jan 7, 2013 12:46 PM
> To:  "gcc-help"<gcc-help@gcc.gnu.org>; 
> 
> Subject:  how to implement this ?
> 
> 
> 
> hi:
> 
>   how to implement this assignment by MACRO?
>   int a,b,c ;
>   
>   ((a==0)?b:c)=8;
> 
>   if use this sentence ,gcc will tell :error: lvalue required as left operand of assignment
> 
>   is there s implementation for this with  macro  define?
> 
>   is there suggestion ?
> 
>   
>   thanks!

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2013-01-07 15:52 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-07 14:31 how to implement this ? horseriver
2013-01-07 14:53 ` Andrew Haley
2013-01-07 15:09   ` horseriver
2013-01-07 15:21     ` Andrew Haley
2013-01-07 15:25       ` horseriver
2013-01-07 15:35         ` Andrew Haley
2013-01-07 15:44           ` horseriver
2013-01-07 15:49             ` Andrew Haley
2013-01-07 15:52               ` horseriver
2013-01-07 17:05                 ` Andrew Haley
2013-01-07 15:30 ugiwgh
2013-01-07 15:39 ` how " horseriver

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).