473,385 Members | 1,267 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,385 software developers and data experts.

variable sized structures.

Hello All!!

Can anybody tell what variable sized structures are and how can they be
used?

regards
--Himanshu
--
comp.lang.c.moderated - moderation address: cl**@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
May 22 '06 #1
4 3127
Himanshu Singh Chauhan wrote:
Hello All!!

Can anybody tell what variable sized structures are and how can they be
used?


You got a couple of answers. Did you look them over. What's the point
in posting multiple times. This is an Usenet group and not a chatroom
which you can keep spamming.

May 23 '06 #2
On 2006-05-22, Himanshu Singh Chauhan <hs********@gmail.com> wrote:
Hello All!!

Can anybody tell what variable sized structures are and how can they be
used?
The term probably refers to a struct whose last member is an array with
no number of elements

struct foo {
int bar;
char baz[];
}

Generally one would use it with malloc(sizeof(struct foo)+n) where n is
the size you want for the flexible member.

regards
--Himanshu

--
comp.lang.c.moderated - moderation address: cl**@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
May 24 '06 #3
Himanshu Singh Chauhan wrote:
Can anybody tell what variable sized structures are and how can they be
used?


It allows for data to be accessible immediately after the structure
itself -- without being separately allocated. Notice, the code below doing
all allocation in a single malloc().

struct meow {
unsigned int size;
struct woof[];
} Meow;

....

static struct meow *
allocate_meow(unsigned int size)
{
struct meow *result;

result = malloc(sizeof(struct meow) + sizeof(struct woof) * size);
if (result == NULL)
return NULL;

result->size = size;
return(result);
}

......

if ((meows = allocate_meow(number)) == NULL)
errx("can not allocate %ud woofs", number);

for (i = 0; i < number; i++)
DO SOMETHING WITH meows.woof[i];
......

How about this?

-mi

--
OMG Pademelons! http://en.wikipedia.org/wiki/Tasmanian_Pademelon
--
comp.lang.c.moderated - moderation address: cl**@plethora.net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
May 24 '06 #4

santosh wrote:
Himanshu Singh Chauhan wrote:
Hello All!!

Can anybody tell what variable sized structures are and how can they be
used?


You got a couple of answers. Did you look them over. What's the point
in posting multiple times. This is an Usenet group and not a chatroom
which you can keep spamming.


Thanks for your help. By the way, to err is humane. Haven't you ever
said, oops!! I clicked wrong button specially when using a mouse pad on
notebook? :-) I am sorry but I had no intentions of spamming, had I had
any, this would have been multiples of multiples, ain't it?

Jun 9 '06 #5

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

Similar topics

0
by: Olli Krollmann | last post by:
hello folks, we have been developing several .NET-based windows forms applications during the last two years. there are two mysterious display problems that we have encountered so far but have...
4
by: Piotr Sawuk | last post by:
Hello, I'm new in this group and new to c++ programming. And I already have my first question which wasn't answered by any text-book on c++ programming I have seen so-far: How can I define a...
13
by: HappyHippy | last post by:
Hi, I'm wondering what you think about this piece of code: #include<iostream> int main() { int size; std::cin >> size;
5
by: frankhall36 | last post by:
Yeah, I need some help, I'm not a very good programmer but I've tried a lot of languages, and anyways, I want to start applying programming to physics, and I would like to learn how to make a...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
4
by: Himanshu Singh Chauhan | last post by:
Hello All!! Can anybody tell what variable sized structures are and how can they be used? regards --Himanshu
3
by: ramkrishna1 | last post by:
Hi All, Consider the following piece of code: struct foo1 { unsigned char tag; unsigned char length; unsigned char value; };
19
by: Spiros Bousbouras | last post by:
Every time I've seen an example of a variable argument list function its functionality was to print formatted output. Does anyone have examples where the function is not some variation of printf ?
3
by: kaffekopp | last post by:
Hi, Since this is the first time for me using fixed size arrays, i would appreciate some guidance to solve this question. First of all, these structures are to be used: struct song { char ...
8
by: Andrew Smallshaw | last post by:
I'm working on a data structure that began life as a skip list derivative, but has evolved to the point that it now only has a passing resemblance to them. Each node of this structure has a few...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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.