473,804 Members | 2,173 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
Richard Tobin wrote:
In article <g3**********@o nline.de>,
Joachim Schmitz <jo**@schmitz-digital.dewrote :
>>Antoninus Twink <no****@nospam. invalidwrites:
[...]
>Just curious: what makes you believe that Antonius Twink is not a
real name?

The fact that you've misread it might be taken as a clue.
True. I only now realized the additional n

Bye, Jojo
Jun 27 '08 #31
Richard wrote:
Ben Bacarisse <be********@bsb .me.ukwrites:
>Antoninus Twink <no****@nospam. invalidwrites:
>>On 15 Jun 2008 at 3:56, vi******@gmail. com wrote:
Thomas: Please change your name to ASCII.

Probably he cares more about making a nationalist point than making
life simpler for people using non-unicode aware
terminals/newsreaders. It's interesting that most Russian, Chinese
and Japanese posters are able to swallow their pride enough to
Latinize their names.

Well, that helps me get a clearer picture of how you see the world.

I think it is quite reasonable that people should be able to spell
their names correctly, but that argument will be lost on someone who
does not even dare let their name be know.

You appear to have totally missed the point. If you re-read Twinks
reply then all the necessary points are therein.

Hint : Most usenet posting Germans convert the German characters to
"oe", "ae" and "ss" etc as appropriate.
In Postings yes, but not neccessarily in Names

Bye, Jojo
Jun 27 '08 #32
Ben Bacarisse <be********@bsb .me.ukwrites:
Antoninus Twink <no****@nospam. invalidwrites:
>On 15 Jun 2008 at 3:56, vi******@gmail. com wrote:
>>Thomas: Please change your name to ASCII.

Probably he cares more about making a nationalist point than making life
simpler for people using non-unicode aware terminals/newsreaders. It's
interesting that most Russian, Chinese and Japanese posters are able to
swallow their pride enough to Latinize their names.

Well, that helps me get a clearer picture of how you see the world.

I think it is quite reasonable that people should be able to spell
their names correctly, but that argument will be lost on someone who
does not even dare let their name be know.
Please don't feed the troll.

--
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 #33
On 15 Jun 2008 at 11:46, Joachim Schmitz wrote:
I think you're missing the point. Tomás wantes to check whether it is safe
to assume that struct {double a;double; double c;} can be interpreted as
double[3], i.e. whether there are any padding bytes in the struct that would
prevent that.
Yes, I got that - I was just commenting on Thomas's seeming confustion
on how floating-point numbers behave.

Jun 27 '08 #34
On 15 Jun 2008 at 11:17, Ben Bacarisse wrote:
Antoninus Twink <no****@nospam. invalidwrites:
>Probably he cares more about making a nationalist point than making life
simpler for people using non-unicode aware terminals/newsreaders. It's
interesting that most Russian, Chinese and Japanese posters are able to
swallow their pride enough to Latinize their names.

Well, that helps me get a clearer picture of how you see the world.
I passed no judgment, but merely tried to explain Thomas's likely
thinking.
I think it is quite reasonable that people should be able to spell
their names correctly, but that argument will be lost on someone who
does not even dare let their name be know.
Thomas can and should do what he likes. I very rarely read Usenet other
than in a Unicode-aware environment, but when I do it's a pain to have
the terminal screwed up by Thomas or Harold van Dijk's non-ASCII
characters. People with strange characters in their name need to decide
whether it's more important to use the "right" spelling of their name,
or to maximize the number of people who can read their messages without
a problem. I pointed out that Thomas makes a decision that's different
from many other people - I neither endorse nor condemn him for that.

Jun 27 '08 #35
Antoninus Twink wrote:
On 15 Jun 2008 at 11:17, Ben Bacarisse wrote:
>Antoninus Twink <no****@nospam. invalidwrites:
>>Probably he cares more about making a nationalist point than making
life simpler for people using non-unicode aware
terminals/newsreaders. It's interesting that most Russian, Chinese
and Japanese posters are able to swallow their pride enough to
Latinize their names.

Well, that helps me get a clearer picture of how you see the world.

I passed no judgment, but merely tried to explain Thomas's likely
thinking.
>I think it is quite reasonable that people should be able to spell
their names correctly, but that argument will be lost on someone who
does not even dare let their name be know.

Thomas can and should do what he likes. I very rarely read Usenet
other than in a Unicode-aware environment, but when I do it's a pain
to have the terminal screwed up by Thomas or Harold van Dijk's
non-ASCII characters. People with strange characters in their name
need to decide whether it's more important to use the "right"
spelling of their name, or to maximize the number of people who can
read their messages without a problem. I pointed out that Thomas
makes a decision that's different from many other people - I neither
endorse nor condemn him for that.
And you mis-transcribe/-spell them, there's no h in Tomás and no o in
Harald. And nothing in these characters is funny.

Bye, Jojo
Jun 27 '08 #36
On Jun 15, 11:46*am, Antoninus Twink <nos...@nospam. invalidwrote:
Probably he cares more about making a nationalist point than making life
simpler for people using non-unicode aware terminals/newsreaders.

Accurate observation, even for a trolling thick.

It's
interesting that most Russian, Chinese and Japanese posters are able to
swallow their pride enough to Latinize their names.

I've always hastened to use the cliché term "There's nothing worse
than X", but in this case they're the only words that come to me:
There's nothing worse than a people without pride. There's plenty of
immigrants in the town where I live. There's Eastern Europeans.
There's black Africans. While I'm not overjoyed with immigrants taking
natives' jobs and accommodation, I don't bear any real animosity or
hatred towards them. Some of them are really nice people, and they're
just here to make a better life for themselves. In fact, their
ambition in life is something a lot of people could aspire to. The
black Africans in particular tend to be extremely pleasant friendly
people; I can smile and say hello to a complete stranger black
African, and he'll say hello back with a warm smile. If I were to do
that to any other stranger, the person would look at me like I'm a
weirdo.

But then there's one immigrant people here that I truly despise: Roma
gypsies. These people have no pride whatsoever. They really are rats.
They come into my country illegally and create encapments at motorway
junctions. They teach their children how to walk in a way that makes
their bare leg look mangled, and then they send their kids to beg
between cars on the road at a busy motorway junction. They have a
mouth full of gold teeth (yes, actual gold, the rare chemical
element), and they drive BMW cars (for those who don't know, BMW is a
luxury car make), but yet they send their children to beg on the
roads. They don't wash their bodies.

Lastnight I was in a shop in my hometime where a friend of mine works.
A Roma gypsie man came up to the counter and asked if anyone could
read a German letter for him. I like to give people the benefit of the
doubt and to be open to friendship with new people, but in this case
this was very naive of me. I read the letter aloud for him. Next, as I
was leaving, he came over to me and snooped around at my car asking me
how much I'd sell it to him for. Again, being naive I plainly told him
"No sorry, I need this car to get to work, it's not for sale" while he
snooped around the car looking in my driver's door.

When I got home, I noticed something was missing. Something which I
had when I was reading the letter for him, but which was gone by the
time I got into my car.

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. There are friends of mine who work in
shops that have had far more experience with Roma gypsies than I have,
but I've never really understood the venomous hatred my friends have
had for them. But now, I understand.

But I digress, there's nothing worse than a people without pride. I'm
Irish, and I'm from Ireland. The vast majority of people in my country
have English names, you'll see "Stephen McAteer" instead of "Stiofán
Mac an tSaoir". Now if they feel comfortable with that, then that's
fine. But personally I don't feel comfortable as an Irish person with
an English name. I'm Irish, I speak Irish and I've an Irish name.
Suits me much better.
Jun 27 '08 #37
Tomás Ó hÉilidhe <to*@lavabit.co mwrites:
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.
Hitler would have agreed with you.
Jun 27 '08 #38
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?
Jun 27 '08 #39
On 15 Jun 2008 at 18:55, Tomás Ó hÉilidhe wrote:
I suggest we drop this conversation, given the forum. Plus it's the
kind of conversation that turns sour very quickly.
Yes, it's amazing how conversations quickly turn sour when someone
introduces a racist tirade into them.

Jun 27 '08 #40

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
9593
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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...
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...
1
7633
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
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
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.