473,473 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

&errno, sizeof errno

Hi all,
A quick one - since errno is a lvalue, can I do:

fread( & errno, sizeof errno, 1, fp )

?
TIA
viza
Sep 12 '08 #1
22 2464
On Fri, 12 Sep 2008 01:22:47 GMT, viza
<to******@gm-il.com.obviouschange.invalidwrote in comp.lang.c:
Hi all,
A quick one - since errno is a lvalue, can I do:
Just because errno is an lvalue, no.

But because errno is required to yield a modifiable lvalue, you would
think so, but not necessarily.

The standard does not require that errno be the name of an object, it
might be a macro.

The standard shows a possible macro implementation in a footnote:

"The macro errno need not be the identifier of an object. It might
expand to a modifiable lvalue resulting from a function call (for
example, *errno())."
fread( & errno, sizeof errno, 1, fp )
The example given in the standard for errno as a macro would work the
way you want.

I can't think of a macro that would expand to a modifiable lvalue and
yet not work, but I'm I could if I put my mind to it, and others here
almost certainly will.

Another potential problem is that fread() is allowed, but not
required, to set the underlying lvalue to any value except 0, in case
of an error or just for the heck of it.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Sep 12 '08 #2

"Jack Klein" <ja*******@spamcop.netwrote in message
news:hk********************************@4ax.com...
On Fri, 12 Sep 2008 01:22:47 GMT, viza
<to******@gm-il.com.obviouschange.invalidwrote in comp.lang.c:
>Hi all,
A quick one - since errno is a lvalue, can I do:

Just because errno is an lvalue, no.

But because errno is required to yield a modifiable lvalue, you would
think so, but not necessarily.

The standard does not require that errno be the name of an object, it
might be a macro.

The standard shows a possible macro implementation in a footnote:

"The macro errno need not be the identifier of an object. It might
expand to a modifiable lvalue resulting from a function call (for
example, *errno())."
>fread( & errno, sizeof errno, 1, fp )

The example given in the standard for errno as a macro would work the
way you want.

I can't think of a macro that would expand to a modifiable lvalue and
yet not work, but I'm I could if I put my mind to it, and others here
almost certainly will.
Ahh, a challange... What if an implementation did something like:

struct {
__flags : 16;
} __errrno;

#define errno (__errno.__flags)

/* :-) */
>
Another potential problem is that fread() is allowed, but not
required, to set the underlying lvalue to any value except 0, in case
of an error or just for the heck of it.
There is that, too...

--
poncho
Sep 12 '08 #3
On Thu, 11 Sep 2008 22:47:27 -0400, Scott Fluhrer wrote:
"Jack Klein" <ja*******@spamcop.netwrote in message
news:hk********************************@4ax.com...
>On Fri, 12 Sep 2008 01:22:47 GMT, viza
<to******@gm-il.com.obviouschange.invalidwrote in comp.lang.c:
>>fread( & errno, sizeof errno, 1, fp )

The example given in the standard for errno as a macro would work the
way you want.

I can't think of a macro that would expand to a modifiable lvalue and
yet not work, but I'm I could if I put my mind to it, and others here
almost certainly will.

Ahh, a challange... What if an implementation did something like:

struct {
__flags : 16;
} __errrno;

#define errno (__errno.__flags)

/* :-) */
If the implementation does that, I would argue that the type of errno is
not int (even if int has 16 bits). Instead, the type is int : 16. Another
possibility is
extern volatile int errno;
where I would argue the type is volatile int.

However, consider this:

register int errno;

Even though user code is not permitted to define static objects with the
keyword register, if this is a supported extension by the implementation,
I don't think any requirements on errno have been violated if the
implementation makes use of it.
Sep 12 '08 #4
On Thu, 11 Sep 2008 22:47:27 -0400, Scott Fluhrer wrote:
"Jack Klein" <ja*******@spamcop.netwrote
>On Fri, 12 Sep 2008 01:22:47 GMT, viza
<to******@gm-il.com.obviouschange.invalidwrote in comp.lang.c:
>>A quick one - since errno is a lvalue, can I do:

fread( & errno, sizeof errno, 1, fp )
>"The macro errno need not be the identifier of an object. It might
expand to a modifiable lvalue resulting from a function call (for
example, *errno())."
>I can't think of a macro that would expand to a modifiable lvalue and
yet not work, but I'm I could if I put my mind to it, and others here
almost certainly will.

Ahh, a challange... What if an implementation did something like:

struct {
__flags : 16;
} __errrno;

#define errno (__errno.__flags)
__errno.__flags is not a "modifiable lvalue of type int".
>Another potential problem is that fread() is allowed, but not required,
to set the underlying lvalue to any value except 0, in case of an error
or just for the heck of it.
Ok, I forgot that the implementation of fread() might write an
intermediate error to errno even in the case of ultimate success.
Sep 12 '08 #5
Harald van Dijk wrote:
On Thu, 11 Sep 2008 22:47:27 -0400, Scott Fluhrer wrote:
>"Jack Klein" <ja*******@spamcop.netwrote in message
news:hk********************************@4ax.com.. .
....
>>I can't think of a macro that would expand to a modifiable lvalue and
yet not work, but I'm I could if I put my mind to it, and others here
almost certainly will.
Ahh, a challange... What if an implementation did something like:

struct {
__flags : 16;
} __errrno;

#define errno (__errno.__flags)

/* :-) */

If the implementation does that, I would argue that the type of errno is
not int (even if int has 16 bits). Instead, the type is int : 16.
A bit-field's width is not part of the type of the bit-field. It merely
determines how much space that bit field takes up. See 6.3.1.1p2, which
says:

"The following may be used in an expression wherever an int or unsigned
int may be used:
....
— A bit-field of type _Bool, int, signed int, or unsigned int."

If the width of a bit-field were part of it's type, the parenthesized
part of 6.3.2.3p5 would be unnecessary: "Two structures share a common
initial sequence if corresponding members have compatible types (and,
for bit-fields, the same widths)".

6.7.2p5 says "Each of the comma-separated sets designates the same type,
except that for bit-fields, it is implementation-defined whether the
specifier int designates the same type as signed int or the same type
as unsigned int."

6.7.2.1p4: "A bit-field shall have a type that is a qualified or
unqualified version of _Bool, signed int, unsigned int, or some other
implementation-defined type."

In each case, the standard talks about the type of a bit field without
while referring only to standard-defined type names, and not referring
to the width.
Sep 12 '08 #6
On Fri, 12 Sep 2008 21:20:28 +0000, James Kuyper wrote:
Harald van Dijk wrote:
>If the implementation does that, I would argue that the type of errno
is not int (even if int has 16 bits). Instead, the type is int : 16.

A bit-field's width is not part of the type of the bit-field. It merely
determines how much space that bit field takes up. [examples snipped]

In each case, the standard talks about the type of a bit field without
while referring only to standard-defined type names, and not referring
to the width.
It's interesting that one of the examples you gave was 6.3.1.1p2. I'll
quote another part of it:

"If an int can represent all values of the original type, the value is
converted to an int; otherwise, it is converted to an unsigned int. These
are called the integer promotions."

Here, "the original type" does include the bit field's width. The standard
is not consistent in treating width as part of the type.
Sep 12 '08 #7
James Kuyper <ja*********@verizon.netwrites:
[...]
A bit-field's width is not part of the type of the bit-field. It
merely determines how much space that bit field takes up. See
6.3.1.1p2, which says:

"The following may be used in an expression wherever an int or
unsigned int may be used:
...
Ñ A bit-field of type _Bool, int, signed int, or unsigned int."
[...]
6.7.2.1p4: "A bit-field shall have a type that is a qualified or
unqualified version of _Bool, signed int, unsigned int, or some other
implementation-defined type."

In each case, the standard talks about the type of a bit field without
while referring only to standard-defined type names, and not referring
to the width.
Agreed. But 6.7.2.1p9 confuses matters slightly:

A bit-field is interpreted as a signed or unsigned integer type
consisting of the specified number of bits.

So, apparently, given:

struct {
unsigned int bf:3;
};

bf *is* of type unsigned int (at least 16 bits), but it's *interpreted
as* an unsigned integer type consisting of 3 bits.

(Though the standard says it's interpreted as a type, it's actually
interpreted as a member of that type.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 12 '08 #8
Harald van Dijk <tr*****@gmail.comwrites:
On Fri, 12 Sep 2008 21:20:28 +0000, James Kuyper wrote:
>Harald van Dijk wrote:
>>If the implementation does that, I would argue that the type of errno
is not int (even if int has 16 bits). Instead, the type is int : 16.

A bit-field's width is not part of the type of the bit-field. It merely
determines how much space that bit field takes up. [examples snipped]

In each case, the standard talks about the type of a bit field without
while referring only to standard-defined type names, and not referring
to the width.

It's interesting that one of the examples you gave was 6.3.1.1p2. I'll
quote another part of it:

"If an int can represent all values of the original type, the value is
converted to an int; otherwise, it is converted to an unsigned int. These
are called the integer promotions."

Here, "the original type" does include the bit field's width.
I don't believe it does.

Here's the context (I'm quoting from n1256, which does differ from
C99; I haven't gone back to check what the change bar refers to):

The following may be used in an expression wherever an int or
unsigned int may be used:

-- An object or expression with an integer type whose integer
conversion rank is less than or equal to the rank of int and
unsigned int. [n1256 has a change bar here]

-- A bit-field of type _Bool, int, signed int, or unsigned int.

If an int can represent all values of the original type, the value
is converted to an int; otherwise, it is converted to an unsigned
int. These are called the _integer promotions_. All other types
are unchanged by the integer promotions.

As far as I can tell, given a bit field "unsigned int bf:3;", the
"original type" of bf is unsigned int.

This does make a difference. If the "original type" is "unsigned
int:3", then the value would be promoted to type int; if the original
type is unsigned int, then the value would be (trivially) promoted to
type unsigned int. But I can't think of a case where the difference
would be visible in the behavior of a program.
The standard
is not consistent in treating width as part of the type.
It's not as clear as it might be, but I *think* it's consistent.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 12 '08 #9
On Fri, 12 Sep 2008 15:32:50 -0700, Keith Thompson wrote:
Harald van Dijk <tr*****@gmail.comwrites:
>It's interesting that one of the examples you gave was 6.3.1.1p2. I'll
quote another part of it:

"If an int can represent all values of the original type, the value is
converted to an int; otherwise, it is converted to an unsigned int.
These are called the integer promotions."

Here, "the original type" does include the bit field's width.

I don't believe it does.
[...]
As far as I can tell, given a bit field "unsigned int bf:3;", the
"original type" of bf is unsigned int.
I picked that sentence so that I could avoid a lengthy discussion in case
of a disagreement. See DR #122. :-)
Sep 13 '08 #10
Harald van Dijk <tr*****@gmail.comwrites:
On Fri, 12 Sep 2008 15:32:50 -0700, Keith Thompson wrote:
>Harald van Dijk <tr*****@gmail.comwrites:
>>It's interesting that one of the examples you gave was 6.3.1.1p2. I'll
quote another part of it:

"If an int can represent all values of the original type, the value is
converted to an int; otherwise, it is converted to an unsigned int.
These are called the integer promotions."

Here, "the original type" does include the bit field's width.

I don't believe it does.
[...]
As far as I can tell, given a bit field "unsigned int bf:3;", the
"original type" of bf is unsigned int.

I picked that sentence so that I could avoid a lengthy discussion in case
of a disagreement. See DR #122. :-)
But DR #122 applies to C90 (which I'm guessing is the reason for the
smiley).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 13 '08 #11
On Sat, 13 Sep 2008 00:56:05 -0700, Keith Thompson wrote:
Harald van Dijk <tr*****@gmail.comwrites:
>On Fri, 12 Sep 2008 15:32:50 -0700, Keith Thompson wrote:
>>Harald van Dijk <tr*****@gmail.comwrites:
It's interesting that one of the examples you gave was 6.3.1.1p2.
I'll quote another part of it:

"If an int can represent all values of the original type, the value
is
converted to an int; otherwise, it is converted to an unsigned int.
These are called the integer promotions."

Here, "the original type" does include the bit field's width.

I don't believe it does.
[...]
As far as I can tell, given a bit field "unsigned int bf:3;", the
"original type" of bf is unsigned int.

I picked that sentence so that I could avoid a lengthy discussion in
case of a disagreement. See DR #122. :-)

But DR #122 applies to C90
Sure, but the text is unchanged between C90 and C99, so I see no reason
for assuming there is a difference in meaning, and I am not aware of C99-
conforming compilers following a different interpretation.
(which I'm guessing is the reason for the smiley).
The smiley was because I figured it would be hard to find any other
example more explicit than that.
Sep 13 '08 #12
Harald van Dijk <tr*****@gmail.comwrites:
On Sat, 13 Sep 2008 00:56:05 -0700, Keith Thompson wrote:
>Harald van Dijk <tr*****@gmail.comwrites:
>>On Fri, 12 Sep 2008 15:32:50 -0700, Keith Thompson wrote:
Harald van Dijk <tr*****@gmail.comwrites:
It's interesting that one of the examples you gave was 6.3.1.1p2.
I'll quote another part of it:
>
"If an int can represent all values of the original type, the value
is
converted to an int; otherwise, it is converted to an unsigned int.
These are called the integer promotions."
>
Here, "the original type" does include the bit field's width.

I don't believe it does.
[...]
As far as I can tell, given a bit field "unsigned int bf:3;", the
"original type" of bf is unsigned int.

I picked that sentence so that I could avoid a lengthy discussion in
case of a disagreement. See DR #122. :-)

But DR #122 applies to C90

Sure, but the text is unchanged between C90 and C99, so I see no reason
for assuming there is a difference in meaning, and I am not aware of C99-
conforming compilers following a different interpretation.
>(which I'm guessing is the reason for the smiley).

The smiley was because I figured it would be hard to find any other
example more explicit than that.
If that was the intent, it's a pity they didn't change the wording in
C99 to reflect that.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 13 '08 #13
viza <to******@gm-il.com.obviouschange.invalidwrites:
On Thu, 11 Sep 2008 22:47:27 -0400, Scott Fluhrer wrote:
"Jack Klein" <ja*******@spamcop.netwrote
On Fri, 12 Sep 2008 01:22:47 GMT, viza
<to******@gm-il.com.obviouschange.invalidwrote in comp.lang.c:
>A quick one - since errno is a lvalue, can I do:

fread( & errno, sizeof errno, 1, fp )
"The macro errno need not be the identifier of an object. It might
expand to a modifiable lvalue resulting from a function call (for
example, *errno())."
I can't think of a macro that would expand to a modifiable lvalue and
yet not work, but I'm I could if I put my mind to it, and others here
almost certainly will.
Ahh, a challange... What if an implementation did something like:

struct {
__flags : 16;
} __errrno;

#define errno (__errno.__flags)

__errno.__flags is not a "modifiable lvalue of type int".
If in some implementation ints are 32 bits, and if we have

struct { int __flags : 32; } __errno;

then how is the type of (__errno.__flags) different from int?
Certainly (__errno.__flags) is a modifiable lvalue.

I understand its address cannot be taken with &, but that's
because it's a bitfield, not because of its type.
Sep 14 '08 #14
On Sep 14, 4:03 pm, Tim Rentsch <t...@alumnus.caltech.eduwrote:
viza <tom.v...@gm-il.com.obviouschange.invalidwrites:
On Thu, 11 Sep 2008 22:47:27 -0400, Scott Fluhrer wrote:
"Jack Klein" <jackkl...@spamcop.netwrote
>On Fri, 12 Sep 2008 01:22:47 GMT, viza
><tom.v...@gm-il.com.obviouschange.invalidwrote in comp.lang.c:
>>A quick one - since errno is a lvalue, can I do:
>>fread( & errno, sizeof errno, 1, fp )
>"The macro errno need not be the identifier of an object. It might
>expand to a modifiable lvalue resulting from a function call (for
>example, *errno())."
>I can't think of a macro that would expand to a modifiable lvalue and
>yet not work, but I'm I could if I put my mind to it, and others here
>almost certainly will.
Ahh, a challange... What if an implementation did something like:
struct {
__flags : 16;
} __errrno;
#define errno (__errno.__flags)
__errno.__flags is not a "modifiable lvalue of type int".

If in some implementation ints are 32 bits, and if we have

struct { int __flags : 32; } __errno;

then how is the type of (__errno.__flags) different from int?
Certainly (__errno.__flags) is a modifiable lvalue.

I understand its address cannot be taken with &, but that's
because it's a bitfield, not because of its type.

Another point: If its type were a bitfield int of 32 bits, then a cast
would make sense;
However, (int : 16) is a syntax error.
Sep 14 '08 #15
James Kuyper <ja*********@verizon.netwrites:
Harald van Dijk wrote:
On Thu, 11 Sep 2008 22:47:27 -0400, Scott Fluhrer wrote:
"Jack Klein" <ja*******@spamcop.netwrote in message
news:hk********************************@4ax.com...
...
>I can't think of a macro that would expand to a modifiable lvalue and
yet not work, but I'm I could if I put my mind to it, and others here
almost certainly will.
Ahh, a challange... What if an implementation did something like:

struct {
__flags : 16;
} __errrno;

#define errno (__errno.__flags)

/* :-) */
If the implementation does that, I would argue that the type of errno is
not int (even if int has 16 bits). Instead, the type is int : 16.

A bit-field's width is not part of the type of the bit-field. It merely
determines how much space that bit field takes up.
The width of a bit-field does affect its type when the
bit-field member is used in an expression.

struct { unsigned bf : 8; } s;
s.bf = 0;
printf( "s.bf - 1 < 1 == %d\n", s.bf - 1 < 1 );

Changing '8' to the number of bits in an unsigned int
will result in a different value.

Sep 14 '08 #16
Tim Rentsch <tx*@alumnus.caltech.eduwrites:
viza <to******@gm-il.com.obviouschange.invalidwrites:
On Thu, 11 Sep 2008 22:47:27 -0400, Scott Fluhrer wrote:
"Jack Klein" <ja*******@spamcop.netwrote
>On Fri, 12 Sep 2008 01:22:47 GMT, viza
><to******@gm-il.com.obviouschange.invalidwrote in comp.lang.c:
>>A quick one - since errno is a lvalue, can I do:
>>>
>>fread( & errno, sizeof errno, 1, fp )
>"The macro errno need not be the identifier of an object. It might
>expand to a modifiable lvalue resulting from a function call (for
>example, *errno())."
>I can't think of a macro that would expand to a modifiable lvalue and
>yet not work, but I'm I could if I put my mind to it, and others here
>almost certainly will.
>
Ahh, a challange... What if an implementation did something like:
>
struct {
__flags : 16;
} __errrno;
>
#define errno (__errno.__flags)
__errno.__flags is not a "modifiable lvalue of type int".

If in some implementation ints are 32 bits, and if we have

struct { int __flags : 32; } __errno;

then how is the type of (__errno.__flags) different from int?
Certainly (__errno.__flags) is a modifiable lvalue.

I understand its address cannot be taken with &, but that's
because it's a bitfield, not because of its type.
Of course, I meant to say 'signed int' rather than 'int' there...
Sep 14 '08 #17
On Sep 14, 4:20 pm, Tim Rentsch <t...@alumnus.caltech.eduwrote:
Tim Rentsch <t...@alumnus.caltech.eduwrites:
viza <tom.v...@gm-il.com.obviouschange.invalidwrites:
struct { int __flags : 32; } __errno;
then how is the type of (__errno.__flags) different from int?
Certainly (__errno.__flags) is a modifiable lvalue.
I understand its address cannot be taken with &, but that's
because it's a bitfield, not because of its type.

Of course, I meant to say 'signed int' rather than 'int' there...
Why? I don't see how your article is wrong without that correction.
Sep 14 '08 #18
vi******@gmail.com writes:
On Sep 14, 4:03 pm, Tim Rentsch <t...@alumnus.caltech.eduwrote:
viza <tom.v...@gm-il.com.obviouschange.invalidwrites:
On Thu, 11 Sep 2008 22:47:27 -0400, Scott Fluhrer wrote:
"Jack Klein" <jackkl...@spamcop.netwrote
On Fri, 12 Sep 2008 01:22:47 GMT, viza
<tom.v...@gm-il.com.obviouschange.invalidwrote in comp.lang.c:
>A quick one - since errno is a lvalue, can I do:
>fread( & errno, sizeof errno, 1, fp )
"The macro errno need not be the identifier of an object. It might
expand to a modifiable lvalue resulting from a function call (for
example, *errno())."
I can't think of a macro that would expand to a modifiable lvalue and
yet not work, but I'm I could if I put my mind to it, and others here
almost certainly will.
Ahh, a challange... What if an implementation did something like:
struct {
__flags : 16;
} __errrno;
#define errno (__errno.__flags)
__errno.__flags is not a "modifiable lvalue of type int".
If in some implementation ints are 32 bits, and if we have

struct { int __flags : 32; } __errno;

then how is the type of (__errno.__flags) different from int?
Certainly (__errno.__flags) is a modifiable lvalue.

I understand its address cannot be taken with &, but that's
because it's a bitfield, not because of its type.


Another point: If its type were a bitfield int of 32 bits, then a cast
would make sense;
However, (int : 16) is a syntax error.
You do realize don't you that this point is irrelevant to the
question that was asked?
Sep 14 '08 #19
vi******@gmail.com writes:
On Sep 14, 4:20 pm, Tim Rentsch <t...@alumnus.caltech.eduwrote:
Tim Rentsch <t...@alumnus.caltech.eduwrites:
viza <tom.v...@gm-il.com.obviouschange.invalidwrites:
struct { int __flags : 32; } __errno;
then how is the type of (__errno.__flags) different from int?
Certainly (__errno.__flags) is a modifiable lvalue.
I understand its address cannot be taken with &, but that's
because it's a bitfield, not because of its type.
Of course, I meant to say 'signed int' rather than 'int' there...

Why? I don't see how your article is wrong without that correction.
Because in bit-fields 'int' is allowed to mean 'unsigned int'
or 'signed int'.
Sep 14 '08 #20
On Sep 14, 5:16 pm, Tim Rentsch <t...@alumnus.caltech.eduwrote:
vipps...@gmail.com writes:
On Sep 14, 4:03 pm, Tim Rentsch <t...@alumnus.caltech.eduwrote:
viza <tom.v...@gm-il.com.obviouschange.invalidwrites:
On Thu, 11 Sep 2008 22:47:27 -0400, Scott Fluhrer wrote:
"Jack Klein" <jackkl...@spamcop.netwrote
>On Fri, 12 Sep 2008 01:22:47 GMT, viza
><tom.v...@gm-il.com.obviouschange.invalidwrote in comp.lang.c:
>>A quick one - since errno is a lvalue, can I do:
>>fread( & errno, sizeof errno, 1, fp )
>"The macro errno need not be the identifier of an object. It might
>expand to a modifiable lvalue resulting from a function call (for
>example, *errno())."
>I can't think of a macro that would expand to a modifiable lvalue and
>yet not work, but I'm I could if I put my mind to it, and others here
>almost certainly will.
Ahh, a challange... What if an implementation did something like:
struct {
__flags : 16;
} __errrno;
#define errno (__errno.__flags)
__errno.__flags is not a "modifiable lvalue of type int".
If in some implementation ints are 32 bits, and if we have
struct { int __flags : 32; } __errno;
then how is the type of (__errno.__flags) different from int?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^
Certainly (__errno.__flags) is a modifiable lvalue.
I understand its address cannot be taken with &, but that's
because it's a bitfield, not because of its type.
Another point: If its type were a bitfield int of 32 bits, then a cast
would make sense;
However, (int : 16) is a syntax error.

You do realize don't you that this point is irrelevant to the
question that was asked?

Actually, no, not really. I was trying to make a point why
__errno.__flags' type is int.
I replied to the question marked with '^', I thought you did the same.
Sep 14 '08 #21
On Sep 14, 5:18 pm, Tim Rentsch <t...@alumnus.caltech.eduwrote:
vipps...@gmail.com writes:
On Sep 14, 4:20 pm, Tim Rentsch <t...@alumnus.caltech.eduwrote:
[correcting an article]
Of course, I meant to say 'signed int' rather than 'int' there...
Why? I don't see how your article is wrong without that correction.

Because in bit-fields 'int' is allowed to mean 'unsigned int'
or 'signed int'.
Oh! Thanks. :-)
Sep 14 '08 #22
vi******@gmail.com writes:
On Sep 14, 5:16 pm, Tim Rentsch <t...@alumnus.caltech.eduwrote:
vipps...@gmail.com writes:
On Sep 14, 4:03 pm, Tim Rentsch <t...@alumnus.caltech.eduwrote:
viza <tom.v...@gm-il.com.obviouschange.invalidwrites:
On Thu, 11 Sep 2008 22:47:27 -0400, Scott Fluhrer wrote:
"Jack Klein" <jackkl...@spamcop.netwrote
On Fri, 12 Sep 2008 01:22:47 GMT, viza
<tom.v...@gm-il.com.obviouschange.invalidwrote in comp.lang.c:
>A quick one - since errno is a lvalue, can I do:
>fread( & errno, sizeof errno, 1, fp )
"The macro errno need not be the identifier of an object. It might
expand to a modifiable lvalue resulting from a function call (for
example, *errno())."
I can't think of a macro that would expand to a modifiable lvalue and
yet not work, but I'm I could if I put my mind to it, and others here
almost certainly will.
Ahh, a challange... What if an implementation did something like:
struct {
__flags : 16;
} __errrno;
#define errno (__errno.__flags)
__errno.__flags is not a "modifiable lvalue of type int".
If in some implementation ints are 32 bits, and if we have
struct { int __flags : 32; } __errno;
then how is the type of (__errno.__flags) different from int?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^
Certainly (__errno.__flags) is a modifiable lvalue.
I understand its address cannot be taken with &, but that's
because it's a bitfield, not because of its type.
Another point: If its type were a bitfield int of 32 bits, then a cast
would make sense;
However, (int : 16) is a syntax error.
You do realize don't you that this point is irrelevant to the
question that was asked?


Actually, no, not really. I was trying to make a point why
__errno.__flags' type is int.
I replied to the question marked with '^', I thought you did the same.
To be more specific -- the question marked with '^' is asking
about how the behavior of (__errno.__flags) doesn't match the
requirement that it be a "modifiable lvalue of type int". It's
true that (int:16) is a syntax error, but that concern is about
how we might /name/ a type, not about what type the expression
(__errno.__flags) has [whether it can be named or not].

Sep 14 '08 #23

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

Similar topics

5
by: Parahat Melayev | last post by:
I am trying to writa a multi-client & multi-threaded TCP server. There is a thread pool. Each thread in the pool will handle requests of multiple clients. But here I have a problem. I find a...
15
by: Alex Vinokur | last post by:
Why does one need to use two kinds of sizeof operator: * sizeof unary-expression, * sizeof (type-name) ? Their behavior seem not to be different (see an example below). ------ C++ code...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.