[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Wrong operators for the binary.



Jose Luis Alarcon wrote:
> --- Tadeusz Andrzej Kadłubowski <yess@hell.org.pl> wrote:
> 
>>On Tue, Dec 03, 2002 at 11:52:03AM -0800, Jose Luis Alarcon wrote:
>>
>>>  Hi all.
>>>
>>>  I am trying compile a module that contains this line:
>>>
>>>     printk("Device: %d.%d\n", inode->i_rdev >> 8, inode->i_rdev & 0xFF);
>>>
>>>and the result is that gcc 3.2.1 says that '>>' and '&' are wrong operators for
>>>the binary. Why?
>>
>>My guess:
>>i_rdev in inode structure is of type kdev_t, which is defined in
>>include/linux/kdev_t.h and contains one member - unsigned short value. Maybe
>>try shifting/bitwise anding not on the structure, but on that particular member
>>of the structure.
>>Then if inode is a pointer to the inode struct, then it would be something
>>like:
>>
>>printk("Device: %d.%d\n", (inode->i_rdev).value >> 8, (inode->i_rdev) & 0xff);
>>
>>This guess obviously may occur wrong. Please tell, if it worked.
>>-- 
>>tadeusz a. kadlubowski
>>
> 
> 
>   Hi Tadeusz, and thanks for your answer.
> 
>   Your proposed line:
> 
>    printk("Device: %d.%d\n", (inode->i_rdev).value >> 8, (inode->i_rdev) & 0xff);
> 
> gets solve the problem for '>>' but not for '&'. I paste here down the output:
> 
> chardev.c:91: wrong operators for the binary &
> 
>   Why gcc think that & is a binary?. I suppose Ori Pomerantz use '>>' and '&' like
> bits level operators.

The operators >> and & are binary operators as opposed to ~ which is a 
unary operator.

I would strongly recommend that you find a copy of K&R (or some C 
language book) and study the bitwise operators and the C types they 
apply to.  Once you understand that, the problem with the line of code 
you tried should be apparent.

HTH,

Eli
--------------------. "If it ain't broke now,
Eli Carter           \                  it will be soon." -- crypto-gram
eli.carter(a)inet.com `-------------------------------------------------

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/