473,583 Members | 3,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What type is a structure?

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?
Nov 14 '05 #1
15 2754

"damian birchler" <da************ *@bluewin.ch> wrote in message
news:29******** *************** **@posting.goog le.com...
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?


Nopes, there is one simple distinction between a structure and array. Think
about the following
struct Human
{
char *name;
int age;
};
Now look at

Human damian;
Human humans[256];
The *primary*distin ction between a structure and an array is that a
structure represents an object/entity as a collection of different
attributes, these attributes may be of different types { above damian has
different attributes name and age }. However in case of an array what you
have is a collection of itmes each having the same type. { humans is an
array, each element of type Human }
--
154

Nov 14 '05 #2
da************* @bluewin.ch (damian birchler) writes:
I'm wondering of what type a structure is. Of course, it is a
_structure_, but an array isn't an _array_ either.
It isn't? That's news to me.
So of what type is a structure? I'd say a pointer, am I right?


No, a structure is not a pointer nor is it similar to a pointer.
--
"The way I see it, an intelligent person who disagrees with me is
probably the most important person I'll interact with on any given
day."
--Billy Chambless
Nov 14 '05 #3
damian birchler wrote:
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?


A struct is a struct is a struct. An array is
an array is an array. A rose is a rose is a rose.
None of them is a pointer is a pointer is a pointer.

You seem to be confused on some really fundamental
matter, but I can't tell what it is. In what way do
you think a struct is a pointer, and why do you think
an array is not an array?

--
Er*********@sun .com

Nov 14 '05 #4
damian birchler wrote:
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?


An array *is* an array. In particular, it is an array-of-T where T is
the type of a element. What type did you think it to be?

A struct *is* a struct. It isn't something else. Why would you think
otherwise.
Nov 14 '05 #5
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?


No.
Perhaps it would help us if you elaborated why you think that an
array is not an array. Otherwise this not so helpful answer certainly
isn't a not so helpful answer.
Guess: You mean an array is not of type "array" but of type "array of
<sometype>".
A structure is exactly of the type you stated it is, that is:

struct {
int x;
char y;
} example;

is of the type "Structure consisting of (in that order) one int,
accessible as x, and one char, accessible as y".

A pointer of type "pointer to <sometype>" contains (if properly
initialized) either NULL or a valid address of an object of type
sometype.

A structure's type is not "pointer".

Note that these explanations are not formally correct; probably
someone else will elaborate or correct what I said.
But I think this helps you more than me posting the respective
parts of the standard:
"6.2.5#20, second item:
A structure type describes a sequentially allocated nonempty set of
member objects (and, in certain circumstances, an incomplete array),
each of which has an optionally specified name and possibly distinct type."
"6.2.7#1
Tw o types have compatible type if their types are the same. Additional
rules for determining whether two types are compatible are described in
6.7.2 for type specifiers, in 6.7.3 for type qualifiers, and in 6.7.5
for declarators.46) Moreover, two structure, union, or enumerated types
declared in separate translation units are compatible if their tags and
members satisfy the following requirements: If one is declared with a
tag, the other shall be declared with the same tag. If both are complete
types, then the following additional requirements apply: there shall be
a one-to-one correspondence between their members such that each pair of
corresponding members are declared with compatible types, and such that
if one member of a corresponding pair is declared with a name, the other
member is declared with the same name. For two structures, corresponding
members shall be declared in the same order. For two structures or
unions, corresponding bit-fields shall have the same widths. For two
enumerations, corresponding members shall have the same values."

Look up the FAQ for pointers, structures and unions as well as types
to help you along:
http://www.eskimo.com/~scs/C-faq/top.html
You can also google for N869, the last C99 draft, which is freely
available. There you can look for struct type and compatibility.
Cheers
Michael

Nov 14 '05 #6
On Fri, 08 Oct 2004 11:12:39 -0700, damian birchler wrote:
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?

Well, you ,the programmer, define _new_ types with e.g. structures.

Nov 14 '05 #7
"damian birchler" <da************ *@bluewin.ch> wrote in message
news:29******** *************** **@posting.goog le.com...
Hi
I'm wondering of what type a structure is.
It is a 'derived type' (see 9899:1999 6.2.5/20), as well as
an 'aggregate type' (see 9899:1999 6.2.5/21), invented by
the definer of the structure.

struct
{
int a;
};

is a type which has no name.

struct x
{
int a;
};

is a type whose name is 'struct x'
Of course, it is a
_structure_, but an array isn't an _array_ either.
Sure it is. Why would you think otherwise? (an array
is also a 'derived' and 'aggregate' type.)
So of what type is
a structure?
See above.
I'd say a pointer, am I right?


Aboslutely not.

A pointer type is a 'derived type' which describes an object
whose value provides a reference to an entity of the referenced
type (commonly said to represent another object's memory address).

What C book(s) are you reading?

-Mike
Nov 14 '05 #8

"Nils O. Selåsdal" <NO*@Utel.no> wrote in message
news:pa******** *************** *****@Utel.no.. .
On Fri, 08 Oct 2004 11:12:39 -0700, damian birchler wrote:
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?

Well, you ,the programmer, define _new_ types with e.g. structures.


More accurately, these are known as 'derived' types.

-Mike
Nov 14 '05 #9

"Mike Wahler" <mk******@mkwah ler.net> wrote in message
news:ev******** *********@newsr ead1.news.pas.e arthlink.net...
A pointer type is a 'derived type' which describes an object
whose value provides a reference to an entity of the referenced
type (commonly said to represent another object's memory address).


For completeness, I must add that a pointer type object can
also represent the predefined value 'NULL', which specifically
indicates 'refers to no object', or 'represents no address'.

-Mike
Nov 14 '05 #10

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

Similar topics

4
1963
by: Clarence | last post by:
Hi - I have a problem and here is the verbose version of what I am trying to do (better too much info than not enough). I am searching through about 4,700 XML files containing company contact details. In the company details are phone numbers. The phone numbers with the formats I need have the following structure. <xs:complexType...
6
4187
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...
100
5206
by: E. Robert Tisdale | last post by:
What is an object? Where did this term come from? Does it have any relation to the objects in "object oriented programming"?
2
5060
by: Tom | last post by:
I'm getting this error when I try to pass a structure to a dll. An unhandled exception of type 'System.ArgumentException' occured in Test1.exe Additional Information: Type could not be marshaled because the length of an embedded array instance does not match the declared length in the layout What does it mean?
669
25769
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990....
1
1703
by: nickolais909 | last post by:
Hello, I have an old C++ DLL that I am wishing to use in a VB.NET program. Previously I had a VB6 program that would pass a Type to a DLL function. For example, I would pass a variable of this Type in: Public Type ListInfo ' structure to hold information about the list file FileIndex As Integer filename(MAXNAME) As Byte FileNum As...
8
40459
by: cman | last post by:
What does this kind of typedef accomplish? typedef struct { unsigned long pte_low; } pte_t; typedef struct { unsigned long pgd; } pgd_t; typedef struct { unsigned long pgprot; } pgprot_t I am familiar with "typedef int NUMBER", but how does it work with structures. Tilak
10
11319
by: giddy | last post by:
hi , I' know what the StructLayoutAttribute does. I've seen it being used. But what does the Pack field do!? This is what MSDN says: Controls the alignment of data fields of a class or structure in memory. This field indicates the packing size that should be used when the LayoutKind.Sequential value is specified. The value of Pack must...
0
1563
by: mvanroshum | last post by:
Hi, I have the following problem: The DataSource of a DataGrid can be set to an IList. The DataGrid nicely lists the objects in the IList, showing all the public properties of the objects as the columns of the datagrid... The public properties with a primitive type are shown The public properties with userdefined types are also shown,...
0
8327
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...
1
7935
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...
0
8193
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...
0
6579
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5374
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...
0
3818
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...
0
3843
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2333
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
0
1157
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...

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.