473,405 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

bit shifting as lvalue

Hi folks,

I'm looking at a problem that has been bugging me for a few days.
It's an forum question/problem that was posted by a reader and I can't
get my head around it. I've tried my due diligence to look this up
myself, but without knowing what the beast is I can't seem to form the
right query. So, now I'm here asking in hopes that the "human touch"
will prove more fruitful. Of course, I shudder to post anything to
c.l.c in fear of being called out as off topic. I certainly didn't
plan on that.

The code is to set up the global descriptor table for the x86
processor (but that's only details)...

Here's what I'm looking at (I've edited so I could get to the point):

struct Segdesc gdt[] =
{
[GD_KT >3] = yadda_yadda_yadda; /* this is the confusing
part */
};

/* what's with the bit shift on the left of the assignment operator??
my impression is 'undefined' or 'non-ISO'. */

struct Segdesc {
unsigned sd_lim_15_0 : 16; // Low bits of segment limit
unsigned sd_base_15_0 : 16; // Low bits of segment base address
unsigned sd_base_23_16 : 8; // Middle bits of segment base address
unsigned sd_type : 4; // Segment type (see STS_ constants)
unsigned sd_s : 1; // 0 = system, 1 = application
unsigned sd_dpl : 2; // Descriptor Privilege Level
unsigned sd_p : 1; // Present
unsigned sd_lim_19_16 : 4; // High bits of segment limit
unsigned sd_avl : 1; // Unused (available for software use)
unsigned sd_rsv1 : 1; // Reserved
unsigned sd_db : 1; // 0 = 16-bit segment, 1 = 32-bit
segment
unsigned sd_g : 1; // Granularity: limit scaled by 4K when
set
unsigned sd_base_31_24 : 8; // High bits of segment base address
};

If anyone can help me understand what the bit shift would do on the
left of an assignment (or point me in the direction of enlightenment)
I would be grateful. The OP in the forum said that this was an
"associated array type of structure". In Perl speak (<puts on flame-
retardant underwear>), this would be a hash, but that's not a
structure native to C and one would have to roll their own (or use a
third-party library)...

Or am I just totally off the reservation on this?

Cheers!

Aug 9 '07 #1
2 1425
jc*****@gmail.com wrote On 08/09/07 14:36,:
Hi folks,

I'm looking at a problem that has been bugging me for a few days.
It's an forum question/problem that was posted by a reader and I can't
get my head around it. I've tried my due diligence to look this up
myself, but without knowing what the beast is I can't seem to form the
right query. So, now I'm here asking in hopes that the "human touch"
will prove more fruitful. Of course, I shudder to post anything to
c.l.c in fear of being called out as off topic. I certainly didn't
plan on that.

The code is to set up the global descriptor table for the x86
processor (but that's only details)...

Here's what I'm looking at (I've edited so I could get to the point):

struct Segdesc gdt[] =
{
[GD_KT >3] = yadda_yadda_yadda; /* this is the confusing
part */
};

/* what's with the bit shift on the left of the assignment operator??
my impression is 'undefined' or 'non-ISO'. */
(Are you sure there's a semicolon after "yadda?" If
it's there I have no idea what's going on -- so I'll
assume it's not really there, and pretend that what *is*
there is either a comma or nothing at all.)

Notice the square brackets around the puzzling
expression. This is one of the new initializer forms
introduced in C99, one that lets you initialize
specific elements in an array. This C90 declaration

int array[] = { 0, 0, 0, 0, 1, 0, 0, 0, 0, 2 };

can be written in C99 as

int array[] = { [4] = 1, [9] = 2 };

(As in C90, any elements you don't mention receive zeroes.
And as in C90, the array size can be calculated from the
initializer list, but slightly differently: In C90 the
array is made large enough to hold as many initializers
as you write, while in C99 it holds the largest-mentioned
intialized element.)

In your example, GC_KT is presumably a macro that
expands to a compile-time constant -- let's suppose it's
twenty-four, so GC_KT >3 is three. Then you've got:

struct Segdesc gdt[] = { [3] = yadda };

.... which creates an array with four elements, initializes
elements [0], [1], and [2] to zeroes, and initializes the
final element [3] to yadda.

--
Er*********@sun.com
Aug 9 '07 #2
jc*****@gmail.com wrote:
On Aug 9, 3:03 pm, Eric Sosman <Eric.Sos...@sun.comwrote:
> (Are you sure there's a semicolon after "yadda?" If
it's there I have no idea what's going on -- so I'll
assume it's not really there, and pretend that what *is*
there is either a comma or nothing at all.)

Yes, sorry, that semicolon was misplaced. I had been typing from
memory.
A point to ponder: When you're baffled by some syntactic
subtlety, are you in a good position to render the problem
faithfully "from memory?"

Hint, Hint, HINT for next time ...

--
Eric Sosman
es*****@ieee-dot-org.invalid
Aug 10 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Hongzheng Wang | last post by:
In K&R, they said: An object is a named region of storage; an lvalue is an expression refer to an object. How about these concept in C++? `The C++ Programming Language' has a similar...
9
by: Steven T. Hatton | last post by:
This is from the draft of the previous version of the Standard: http://www.kuzbass.ru:8086/docs/isocpp/expr.html 2- A literal is a primary expression. Its type depends on its form...
9
by: GGG | last post by:
Noticed something odd in the way bit shifting was working today. As far as I have ever heard, shifting will shift in zeros(signed ints aside) However I foudn something odd when I am shifting...
15
by: Michael Baehr | last post by:
I recently upgraded my Arch Linux system to GCC 3.4, and found out that a previously accepted behavior (cast-as-lvalue) is now marked as deprecated, and will cease to function in GCC 3.5. This has...
24
by: Romeo Colacitti | last post by:
Hi, Does anyone here have a strong understanding for the meanings of the terms "lvalue" and "rvalue" as it pertains to C, objects, and different contexts? If so please share. I've been...
9
by: junky_fellow | last post by:
Consider the following piece of code: (char *)0x100; /* I know that converting an integer to pointer type is implementation defined. But forget this for a moment */ My question is, Why the...
3
by: Kavya | last post by:
Can someone give and explain in simple terms a definition of lvalue? Also what are these modifiable and non-modifiable lvalues? I always thought that, if we can assign to anything then that...
10
by: the_init | last post by:
Hi friends, I read about Lvalue in previous posting and Googled it but I'm not understood it completely. There is a small doubt. int a; a=20; // here a is Lvalue But
14
by: nobrow | last post by:
Yes I know what lvalue means, but what I want to ask you guys about is what are all valid lvalues ... a *a a *(a + 1) .... What else?
16
by: lak | last post by:
i know left and right shift normally,but i cant know what happens if it is negative. for example int x=-2; x<<=1;//what happens here
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
agi2029
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,...
0
isladogs
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.