473,378 Members | 1,507 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

What happens when I write struct xx_type {...}


Hello,

to promote data-hiding I have come across the following technique,
which I quite like:

Header file xxx.h:
------------------
typedef struct xxx_type xxx_type;
xxx_type * xxx_alloc(int);
-------------------------

Source file xxx.c:
-----------------
struct xxx_type {
double *data;
int size;
};

xxx_type * xxx_alloc(int size) {
xxx_type *xxx;
xxx = malloc(sizeof *xxx);
xxx->size = size;
....
return xxx;
}
-------------------------
What I wonder is what really happens at the struct xxx_type {};
statement in the source file. To me it seems like a struct is defined,
but it is not used for anything - i.e. not for a typedef nor to
instantiate an object.

So - I guess I my question is really: "What does the compiler do -
when it meets a

struct foo {
....
....
};

statement.
Best Regards

Joakim Hove

--
Joakim Hove
hove AT ntnu.no /
Tlf: +47 (73 5)9 34 27 / Stabburveien 18
Fax: ................. / N-5231 Paradis
http://www.ift.uib.no/~hove/ / 55 91 28 18 / 92 68 57 04
Aug 29 '06 #1
1 1281
Joakim Hove wrote:
>
.... snip ...
>
So - I guess I my question is really: "What does the compiler do -
when it meets a

struct foo {
....
....
};

statement.
It defines a new type, known as "struct foo", which you can now use
in defining storage, parameters, etc. typedef DOES NOT define a
new type, it simply defines a synonym for the already defined type.

--
Chuck F (cb********@yahoo.com) (cb********@maineline.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.netUSE maineline address!
Aug 29 '06 #2

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

Similar topics

12
by: Steven T. Hatton | last post by:
This is something I've been looking at because it is central to a currently broken part of the KDevelop new application wizard. I'm not complaining about it being broken, It's a CVS images. ...
51
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is...
15
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?
43
by: Mountain Bikn' Guy | last post by:
I have a situation where an app writes data of various types (primitives and objects) into a single dimensional array of objects. (This array eventually becomes a row in a data table, but that's...
2
by: Peter Oliphant | last post by:
This is possibly some other problem, but here goes anyway. I created a 'value struct'. I then created a stack semantic instance of it. I then created a method that takes a pointer to such an...
2
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include...
5
by: Steven T. Hatton | last post by:
I wish I had an example so I could demonstrate. This is something I've wanted to understand for a long time, but every time I've hit it, I've been too busy to stop and investigate. Sometimes when...
23
by: Jess | last post by:
Hello, I understand the default-initialization happens if we don't initialize an object explicitly. I think for an object of a class type, the value is determined by the constructor, and for...
4
by: ianbrn | last post by:
Hello, I have a struct defined thus: typedef struct myStruct { int j; } myStruct; I saw somewhere calls with the following syntax: f1(&*a)
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.