473,796 Members | 2,688 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 2444
pereges <Br*****@gmail. comwrote:
On Jun 17, 3:43 pm, Keith Thompson <ks...@mib.orgw rote:
Great. But why use the name "_vector"? If you insist on having
disinct names for the struct tag and the typedef, you could use a
trailing underscore or a "_s" suffix. For that matter, you could
just drop the struct tag:

typedef struct {
double coord[3];
} vector;

The only reason why I do it is because some times I have come across
situations which require self referential structures.
Why bother making them different in the first place? struct names live
in a namespace of their own; you can easily do

typedef struct tree {
struct tree *left;
struct tree *right;
unsigned long payload;
} tree;

It's quite legal.

Richard
Jun 27 '08 #81
Antoninus Twink wrote:
On 16 Jun 2008 at 18:46, santosh wrote:
>Again you fail to understand that there is such a thing called
topicality. Even you must admit that the current subject is simply
not topical in clc. And it's not hair-splitting or pedanticism
either. The subject is *massively* off-topic.

Why not tell that to Richard Heathfield, Keith Thompson, Flash Gordon,
CBFalconer, Nick Keighley, and one... santosh, who have all taken an
active part in this discussion?
Because you were the only one to protest against Keith Thompson's
request to Tomás to observe his own statement to cease the conversation
due to it's off-topic nature. No one has to my knowledge disputed
Tomás's right to air his opinions. It's just a matter of respecting
topicality, which even Tomás agrees with. You of course would like all
discussions on all possible subjects to take place in clc. What's the
matter, doesn't your Usenet server carry any other group beside clc?

Jun 27 '08 #82
Richard Heathfield wrote:
santosh said:
>Antoninus Twink wrote:
>>On 16 Jun 2008 at 0:34, Keith Thompson wrote:
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.

However unpleasant you may find Thomas's racist views, don't you
believe even more strongly that he has a right to free speech?

Again you fail to understand that there is such a thing called
topicality. Even you must admit that the current subject is simply
not topical in clc. And it's not hair-splitting or pedanticism
either. The subject is *massively* off-topic.

I agree that it's off-topic. For once I actually agree with Mr Twink,
too: Tomas has the right to peddle his revolting opinions in public if
he wishes.
Yes of course.
But we are not obliged to listen. And this is supposed to
be a techie group, not a sounding-board for racists.
My point exactly, and I suspect Keith's too.
>Why not move it to soc.culture.iri sh or somewhere similar?

I think it would be more appropriate to move it to alt.racist.bigo t,
don't you?
Perhaps. But if enough Irish do have broadly similar sentiments as Tomás
(and I'm not saying that they do or not do) then it might reasonably be
considered as topical in a group dealing with Irish society.
But of course, realistically it's way too late to move the
discussion anywhere. There is a certain inertia to a thread, and each
new participant increases that inertia, because it gets harder and
harder to get everyone to agree to subscribe to the new group and
continue the thread therein.
Jun 27 '08 #83
santosh <sa*********@gm ail.comwrites:
Antoninus Twink wrote:
>On 16 Jun 2008 at 18:46, santosh wrote:
>>Again you fail to understand that there is such a thing called
topicality. Even you must admit that the current subject is simply
not topical in clc. And it's not hair-splitting or pedanticism
either. The subject is *massively* off-topic.

Why not tell that to Richard Heathfield, Keith Thompson, Flash Gordon,
CBFalconer, Nick Keighley, and one... santosh, who have all taken an
active part in this discussion?

Because you were the only one to protest against Keith Thompson's
request to Tomás to observe his own statement to cease the conversation
due to it's off-topic nature. No one has to my knowledge disputed
Tomás's right to air his opinions. It's just a matter of respecting
topicality, which even Tomás agrees with. You of course would like all
discussions on all possible subjects to take place in clc. What's the
matter, doesn't your Usenet server carry any other group beside clc?
You seem to have missed the point. Having elevated yourself into the
ranks of the pedantic "regs" you feel it is OK for YOU to post OT to
threads which are considered "OT" in c.l.c.

Having said that Tomas' thread was highly unsavoury and would not really
be welcome anywhere.

Jun 27 '08 #84
ra**********@gm ail.com wrote:
Tomás Ó hÉilidhe <t...@lavabit.c omwrote:
.... snip ...
>
>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.

In my experience what you've described is indeed true, but I
always say these are the selected lot that have come over here
to abuse the system.

I have to say this, as xenophobic as Tom may seem, what he
describes even I cannot deny as being ludicrous or far from the
truth. Treating them as people to avoid like hell on the street
(Just as you would any other rough looking type or tramp), is one
thing. You can tell they are trouble, and you will want to stay
clear.
Congratulations . You just joined him on the bigot plonk list.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
** Posted from http://www.teranews.com **
Jun 27 '08 #85
santosh <sa*********@gm ail.comwrites:
Antoninus Twink wrote:
[more of the same]
Because you were the only one to protest against Keith Thompson's
request to Tomás to observe his own statement to cease the conversation
due to it's off-topic nature. No one has to my knowledge disputed
Tomás's right to air his opinions. It's just a matter of respecting
topicality, which even Tomás agrees with. You of course would like all
discussions on all possible subjects to take place in clc. What's the
matter, doesn't your Usenet server carry any other group beside clc?
santosh, 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 #86

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

Similar topics

19
6877
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
4206
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
2416
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
2134
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
35801
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
3800
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
9673
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
10221
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
10169
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
10003
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
7546
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
6785
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
5569
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
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.