473,804 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How come C allow structure members to be addressed like an array ?

#include <stdio.h>

typedef struct
{
double x, y, z;
}vector;

int main(void)
{
int i;
vector v;
double *cord;

v.x = 10;
v.y = 1;
v.z = 2;

cord = &v.x;

for(i = 0; i < 3; i++)
{
printf("%f\n", cord[i]);
}
return 0;
}

here's the output i get:
10.000000
1.000000
2.000000

which is the same as v

i don't how it happens as i was just trying some random ideas but
great stuff really. helped me to reduce some of my code to almost
1/3rd its size.
Jun 27 '08
85 2448
On Jun 14, 10:37*pm, pereges <Brol...@gmail. comwrote:
i don't how it happens as i was just trying some random ideas but
great stuff really. helped me to reduce some of my code to almost
1/3rd its size.
What you are doing invokes undefined behaviour.

As soon as you are using an optimising compiler, there are excellent
chances that your code will run into serious trouble.

For example, optimising compilers will often keep all the members of a
struct in registers; so whether a program uses your "vector" or three
doubles would make no difference. Since you take the address of v.x,
the compiler could decide to put v.x into memory, and v.y and v.z into
two floating-point registers. Your loop prints v.x plus the contents
of the memory following it, instead of v.y and v.z. This is legal and
correct under the "as if" rule.

Jun 27 '08 #41
Tomás Ó hÉilidhe said:

<snip>
But then there's one immigrant people here that I truly despise: Roma
gypsies.
<snipped: anecdote of alleged theft by Roma gypsy>
Now up until that point, I'd never been a fan of Roma gypsies, but at
the same time I'd no real animosity or hatred for them. Now though, I
don't even see them as people.
<snip>
But I digress, there's nothing worse than a people without pride. I'm
Irish, and I'm from Ireland.
One Roma gypsy (allegedly) steals from you, and now you say that, as a result
of this, you don't even see them as people.

Quite a few Irish people have been responsible for the indiscriminate killing
of a great many people since the 1960s. By *your* logic, we should despise
the Irish and not see /them/ as people. We should accord them no rights, and
give them no quarter.

Fortunately for the world, not everyone is as bigoted as you.

Tarring an entire people with a single brush is /never/ appropriate.

<snip>

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #42
Richard Heathfield <rj*@see.sig.in validwrites:
Tomás Ó hÉilidhe said:

<snip>
>But then there's one immigrant people here that I truly despise: Roma
gypsies.

<snipped: anecdote of alleged theft by Roma gypsy>
>Now up until that point, I'd never been a fan of Roma gypsies, but at
the same time I'd no real animosity or hatred for them. Now though, I
don't even see them as people.

<snip>
>But I digress, there's nothing worse than a people without pride. I'm
Irish, and I'm from Ireland.

One Roma gypsy (allegedly) steals from you, and now you say that, as a result
of this, you don't even see them as people.

Quite a few Irish people have been responsible for the indiscriminate killing
of a great many people since the 1960s. By *your* logic, we should despise
the Irish and not see /them/ as people. We should accord them no rights, and
give them no quarter.

Fortunately for the world, not everyone is as bigoted as you.

Tarring an entire people with a single brush is /never/ appropriate.

<snip>
I find it interesting that Twink's initial guess at the pretentious
insistence on the Irish spelling (which IS a pain the arse for non
unicode compliant newreaders and browsers) was actually quite
correct. As an Irish man myself I would like to distance myself and
others from the ridiculously blatant hatred and racism shown by Tomas
above. It is a sad reflection on current life in Ireland that the boom
in immigration has revealed many people to be worse than those (the
English) they have criticised for so many years.

Jun 27 '08 #43
Richard wrote:
Richard Heathfield <rj*@see.sig.in validwrites:
>Tomás Ó hÉilidhe said:

<snip>
>>But then there's one immigrant people here that I truly despise:
Roma gypsies.

<snipped: anecdote of alleged theft by Roma gypsy>
>>Now up until that point, I'd never been a fan of Roma gypsies, but
at the same time I'd no real animosity or hatred for them. Now
though, I don't even see them as people.

<snip>
>>But I digress, there's nothing worse than a people without pride.
I'm Irish, and I'm from Ireland.

One Roma gypsy (allegedly) steals from you, and now you say that, as
a result of this, you don't even see them as people.

Quite a few Irish people have been responsible for the indiscriminate
killing of a great many people since the 1960s. By *your* logic, we
should despise the Irish and not see /them/ as people. We should
accord them no rights, and give them no quarter.

Fortunately for the world, not everyone is as bigoted as you.

Tarring an entire people with a single brush is /never/ appropriate.

<snip>

I find it interesting that Twink's initial guess at the pretentious
insistence on the Irish spelling (which IS a pain the arse for non
unicode compliant newreaders and browsers) was actually quite
correct. As an Irish man myself I would like to distance myself and
others from the ridiculously blatant hatred and racism shown by Tomas
above. It is a sad reflection on current life in Ireland that the boom
in immigration has revealed many people to be worse than those (the
English) they have criticised for so many years.
Can the Roma properly be called as immigrants? One would've thought that
they have a presence in Ireland for at least a few centuries now.

Jun 27 '08 #44
On 15 Jun 2008 at 18:26, santosh wrote:
Can the Roma properly be called as immigrants? One would've thought that
they have a presence in Ireland for at least a few centuries now.
I believe Thomas was directing his racist rant against immigrant Roma
gypsies specifically, rather than the home-grown/naturalized Irish
tinkers.

Jun 27 '08 #45
On Jun 15, 6:57*pm, Richard Heathfield <r...@see.sig.i nvalidwrote:
<snipped: anecdote of alleged theft by Roma gypsy>

I've just been back from that shop I was in and my mate had a look
over the cameras with me. I put the object on the roof of my car as I
was talking to the gypsie, and as I turned around to unlock my door he
swiped it an put it in his coat. The camera shows it clearly.

One Roma gypsy (allegedly) steals from you, and now you say that, as a result
of this, you don't even see them as people.

Not allegedly, definitely. Witnessing their thievery first-hand was
the straw that broke the camel's back. Up until then I was well aware
of their reputation as being a dirty filthy race of people, but the
idea hadn't been cemented in my mind as I hadn't witnessed it first-
hand.

Quite a few Irish people have been responsible for the indiscriminate killing
of a great many people since the 1960s. By *your* logic, we should despise
the Irish and not see /them/ as people. We should accord them no rights, and
give them no quarter.

If I'd been robbed by a German I would _not_ have tarred them all with
the same brush. Same goes for an American. Or a Japanese person.

Roma gypsies are a different animal altogether.

Fortunately for the world, not everyone is as bigoted as you.

Tarring an entire people with a single brush is /never/ appropriate.

People have prejudices for a reason. If I had no prejudice, I'd be
robbed daily. From now on, I won't allow a Roman gypsie within a foot
of me.

I suggest we drop this conversation, given the forum. Plus it's the
kind of conversation that turns sour very quickly. If you really want
to continue you can send me private e-mail.
Jun 27 '08 #46
On Jun 15, 10:28*pm, Richard Heathfield <r...@see.sig.i nvalidwrote:
If I paid attention to the opinions of bigots, I'd be at risk of becoming a
bigot myself. But I'm not going to assume that all Irishmen are bigots, just
because you are.

The word "bigot" isn't used by my generation, I had to look it up. I
got the following definition from the internet:

"A person who is utterly intolerant of any differing creed, belief, or
opinion."

Whether I am tolerant of a particular people depends entirely on the
people in question. Does that not make perfect sense? I know all kinds
of people, all different nationalities and religions. I know
Catholics, Muslims, Sikhs, Hindus, a few other religions. I know
blacks, whites, asians. I know Nigerians, Scottish, Americans, French,
Germans, Belgians. My college was full of all sorts of people from all
different backgrounds, and I got on fine with all of them.

Of all the races, creeds, religions, nationalities, what have you, in
the world, I'm prejudiced against one sole group: Roma gypsies, and
it's purely from my own personal experience with them.

That's a pretty good "tolerance track record" if you ask me. And it's
not like I'm about to start a campaign for Ethnic cleansing... I'm
just not going to let a Roma gypsie near me ever again. If they come
within a metre, I'll raise my fist out in front of them and tell them
to get away from me. If they proceed further, they're going home with
less teeth. I think that's the fairest I can be about it.

I suggest you drop the racism, for your own sake. Hatred is not good for you.

Thanks for the advice, and I agree with it. But having all the warmth
in the world in my hearth won't stop Roma gypsies from exploiting
their kids and robbing me.

I don't so much have a hatred for them, I just view them as a dirty
filthy people.

I have nothing to say to you in private. It seems clear that there isn't much
point saying anything to you in public, either. So - welcome to my bozo bin.

A rare honour, I had assumed you didn't have a killfile.
Jun 27 '08 #47
Tomás Ó hÉilidhe <to*@lavabit.co mwrites:
On Jun 15, 8:53*pm, Keith Thompson <ks...@mib.orgw rote:
>You are of course free to accept or ignore my advice.

I post from Google Groups. Does Google Groups not do the character
encoding thing on my name?
I don't know. Do your own research.

--
Keith Thompson (The_Other_Keit h) 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"
Jun 27 '08 #48
Tomás Ó hÉilidhe wrote, On 15/06/08 22:56:
On Jun 15, 10:28 pm, Richard Heathfield <r...@see.sig.i nvalidwrote:
>If I paid attention to the opinions of bigots, I'd be at risk of becoming a
bigot myself. But I'm not going to assume that all Irishmen are bigots, just
because you are.

The word "bigot" isn't used by my generation,
Am I that old? Well, back in the 80's I found that a word I knew well
and understood was not known by someone only a year younger than me, so
perhaps it is just my background.
I had to look it up. I
got the following definition from the internet:

"A person who is utterly intolerant of any differing creed, belief, or
opinion."
Another definition is "a person obstinately or intolerantly devoted to
his or her own opinions and prejudices; especially : one who regards or
treats the members of a group (as a racial or ethnic group) with hatred
and intolerance". Note that this definition does not specify *all* other
groups, just one. In that respect it meets the usage that I know.

<snip>
Thanks for the advice, and I agree with it. But having all the warmth
in the world in my hearth won't stop Roma gypsies from exploiting
their kids and robbing me.

I don't so much have a hatred for them, I just view them as a dirty
filthy people.
<snip>

My experience is that is is modern "travellers " who are the problem not
real gypsies. However, I am certain that it is not all "travellers " just
as I am certain that the bigoted opinion some people I know have against
the people of India is in general wrong.
--
Flash Gordon
With Jewish and lots of other blood running through my veins.
Jun 27 '08 #49
Tomás Ó hÉilidhe <to*@lavabit.co mwrites:
[...]
I don't so much have a hatred for them, I just view them as a dirty
filthy people.
[...]

Upthread, you wrote:

I suggest we drop this conversation, given the forum.

This will not end until you end it. Stop talking about the "Roma
gypsies", right now. Don't respond to this. Don't try to defend
your opinions. Just shut the hell up about it.

--
Keith Thompson (The_Other_Keit h) 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"
Jun 27 '08 #50

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

Similar topics

19
6879
by: Thomas Matthews | last post by:
Hi, Given a structure of pointers: struct Example_Struct { unsigned char * ptr_buffer; unsigned int * ptr_numbers; }; And a function that will accept the structure:
4
2825
by: Thomas Matthews | last post by:
Hi, I'm writing code for an embedded system. In the system a Timer has 4 memory mapped registers of 32-bit lengths in contiguous locations: Timer 0: 0x1000 Configuration register 0x1004 Control register 0x1008 Input register 0x100C Output register.
6
4207
by: Eric Smith | last post by:
Is a structure containing an incomplete array as its last element (per paragraph 2 of section 6.7.2.1 of ISO/IEC 9899:1999 (E)) itself an incomplete type? That appears to be indicated by paragraph 22 of section 6.2.5. If so, that seems to make it difficult to allocate such structures, because sizeof() is not allowed on incomplete types (paragraph 1 of section 6.5.3.4). For instance, I've routinely done things like this: struct foo {...
11
2419
by: Mannequin* | last post by:
Hi all, I'm working on a quick program to bring the Bible into memory from a text file. Anyway, I have three questions to ask. First, is my implementation of malloc () correct in the program to follow? Second, have I correctly passed the structure's pointer to the functions in this program?
15
2789
by: damian birchler | last post by:
Hi I'm wondering of what type a structure is. Of course, it is a _structure_, but an array isn't an _array_ either. So of what type is a structure? I'd say a pointer, am I right?
10
2135
by: nambissan.nisha | last post by:
I am facing this problem.... I have to define a structure at runtime as the user specifies... The user will tell the number of fields,the actual fields...(maybe basic or array types or multiple arrays,etc) I do not understand how to define the structure at run time.i.e.what fields it will contain.
6
3026
by: noone | last post by:
What is the syntax to access members of a structure without explicitly naming the structure in every access? struct mytype { int a; char* b; long c; } IT; How can I access the structure members in a way similar to the old pascal
5
35806
Banfa
by: Banfa | last post by:
I thought I would write a little article about this because it is regularly asked as a question in the Forums. Firstly this is a C++ issue, it is strictly against the rules of C to create a class with no members. This makes sense because the only real use for a structure or class with no data members and virtual functions is as the base from which to derive other classes and structures or as a container for non-virtual methods. The reason...
5
3803
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);" I thought that it is very hard to memory map structure array. I need both read and write memory mapped file at both side of C# and C++.
0
9711
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10595
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10335
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5529
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4306
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 we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.