how much memory is allocated for following structure
struct bharath
{
int b;
char c;
float d;
}
and how?
Jun 21 '07
43 2383
On Thu, 21 Jun 2007 14:56:39 -0000, in comp.lang.c ,
"bh********@gma il.com" <bh********@gma il.comwrote:
> what i want actually is how much size will be allocated for above structuer in a 16 bit machine
There is no correct answer. Depending on compiler settings, hardware
requirements and so on, it could be anything from seven bytes upwards.
Its impossible to say.
Why do you need to know?
--
Mark McIntyre
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
"bh********@gma il.com" wrote:
>
how much memory is allocated for following structure
struct bharath {
int b;
char c;
float d;
}
and how?
Exactly "sizeof(str uct bjarath);", in bytes. How is system
dependant.
--
<http://www.cs.auckland .ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfoc us.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net
--
Posted via a free Usenet account from http://www.teranews.com bh********@gmai l.com wrote:
how much memory is allocated for following structure
struct bharath
{
int b;
char c;
float d;
}
This is, for some reason, a common newbie question. It doesn't need to
be. When it comes to struct sizes, there are only two things to keep in
mind:
1. The actual size is implementation-specific. That means it varies
from compiler to compiler, perhaps even with the same compiler
depending on options. There's no way to know from code inspection.
2. When you need to know the size in a program, the sizeof operator
will tell you. The actual value is of little importance.
Brian bh********@gmai l.com wrote:
how much memory is allocated for following structure
struct bharath
{
int b;
char c;
float d;
}
^^ ';' needed
None, until an instance of that structure is declared.
If you have one
struct bharath foo;
the space allocated is
sizeof foo
or
sizeof(struct bharath)
and is at least
sizeof(int)+siz eof(float)+1
and how?
With whatever mechanism your compiler allocates space for other variables.
<bh********@gma il.comha scritto nel messaggio news:11******** **************@ q19g2000prn.goo glegroups.com.. .
how much memory is allocated for following structure
struct bharath
{
int b;
char c;
float d;
}
None, because you are not declaring an object.
If you wrote
struct bharath {
int b;
char c;
float d;
} a;
It would allocate sizeof a bytes, i.e. sizeof(struct bharath)
bytes.
and how?
The same way it is allocated for any other object.
<bh********@gma il.comha scritto nel messaggio news:11******** *************@q 19g2000prn.goog legroups.com...
On Jun 21, 7:49 pm, Clever Monkey <spamt...@cleve rmonkey.org.INV ALID>
wrote:
>balu wrote:
On Jun 21, 7:33 pm, Richard Heathfield <r...@see.sig.i nvalidwrote: bharath...@gma il.com said:
>>how much memory is allocated for following structure struct bharath { int b; char c; float d; } None. It's a type, not an object.
[Please use a newsreader that understands how to trim sigs, or trim them yourself. I've done this for you here.]
let the int size is 4B then the allocation will be?
i want to know the info regarding padding or some other else related
to padding?
This is exactly the sort of thing that people talk about when they say something is implementation specific. That is, once you actually allocate for a type, the specifics of how that memory is allocated is not necessarily dictated by the Standard.
Simply defining (or is it declaring?) the type, of course, allocates no memory. -- clvrmnky <mailto:spamt.. .@clevermonkey. org>
Direct replies will be blacklisted. Replace "spamtrap" with my name to contact me directly.
what i want actually is how much size will be allocated for above
structuer in a 16 bit machine
It doesn't even have to be the same on all 16-bit machines, or even
on the same machine with different compilers.
"bh********@gma il.com" <bh********@gma il.comwrites:
how much memory is allocated for following structure
struct bharath
{
int b;
char c;
float d;
}
and how?
The comp.lang.c FAQ is at <http://www.c-faq.com/>. Section 2 covers
structures (as well as unions and enumerations). Read it. If you're
still confused, come back and ask again.
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister" bh********@gmai l.com wrote:
On Jun 21, 7:49 pm, Clever Monkey <spamt...@cleve rmonkey.org.INV ALID>
wrote:
>balu wrote:
On Jun 21, 7:33 pm, Richard Heathfield <r...@see.sig.i nvalidwrote: bharath...@gma il.com said:
>>how much memory is allocated for following structure struct bharath { int b; char c; float d; }
(fx:snipping)
what i want actually is how much size will be allocated for above
structuer in a 16 bit machine
It depends on the implementation.
Really.
A "16-bit machine" (and what /that/ means isn't unambiguous) might have
a C implementation which used 32-bit ints. Or 16-bit ints. It might have
32-bit floats. Or 64. Floats might need to be allocated on 16-bit boundaries.
Or 32-bit boundaries. Or 8-bit boundaries. chars might be 8 bits wide.
Or 16. You might be able to /select/ these things with, say, command-line
switches.
It depends on the implementation.
--
Chris "just like life, really" Dollin
Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England
"bh********@gma il.com" <bh********@gma il.comwrote:
# how much memory is allocated for following structure
None. Structures only exist in the compiler; in the code
you have blocks of allocated memory and offsets into them.
A variable of type T needs no more than sizeof(T) char sized
units allocated on appropriate memory boundary.
# struct bharath
# {
# int b;
# char c;
# float d;
# }
A variable of type (struct bharath) will be allocated at
least sizeof(struct bharath) bytes. How a compiler allocates
the space is really up to the compiler. If you need to know
there are field offset macros to find otu where each field
begins in the variable's allocated space.
--
SM Ryan http://www.rawbw.com/~wyrmwif/
I hope it feels so good to be right. There's nothing more
exhilarating pointing out the shortcomings of others, is there? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Berk Birand |
last post by:
Hi all,
I have to use C-style structures for an assignement. I cannot have any
methods or constructors for it. What has surprised me is that in my
code, I have to allocate memory for an array of structures with malloc.
Otherwise, I get a seg fault. Here's the code:
struct Employee {
char* name; // Pointer to character string holding name of employee.
int salary;
|
by: Thomas Paul Diffenbach |
last post by:
Can anyone point me to an open source library of /statically
allocated/ data structures?
I'm writing some code that would benefit from trees, preferably self
balancing, but on an embedded system that doesn't offer dynamic
memory allocation (to be clear: no malloc, no realloc), and with
rather tight memory constraints.
Writing my own malloc to do dynamic allocation from some static pool
isn't really an option, for various reasons, not...
|
by: Peter Smithson |
last post by:
Hi,
I've read this page -
http://devrsrc1.external.hp.com/STK/impacts/i634.html
but don't understand it. Here's the text -
"Non-standard usage of setjmp() and longjmp() could result in
compatibility problems. The contents of the jmp_buf buffer are specific
|
by: Joe.ntang |
last post by:
Hi,
The following function is what I want to call,
int
DbEnv::memp_stat(DB_MPOOL_STAT **gsp,
DB_MPOOL_FSTAT *(*fsp), u_int32_t flags);
The function has following description:
|
by: skumar434 |
last post by:
Hi everybody,
I am faceing problem while assigning the memory dynamically to a array
of structures .
Suppose I have a structure
typedef struct hom_id{
int32_t nod_de;
int32_t hom_id;
| |
by: svata |
last post by:
Hello,
I wonder how to resize such array of structures using realloc()?
#include <stdio.h>
#include <stdlib.h>
#define FIRST 7
typedef struct {
char *name;
|
by: TefJlives |
last post by:
Hi all,
I'm learning a bit about C, and I have a few questions. I'm not trying
to insult C or anything with these questions, they're just honestly
things I don't get.
It seems like pointers to chars are just how you deal with strings, and
pointers to pointers to char just give you arrays of strings. What is
the advantage of this vs. languages with a string type?
|
by: TommyB |
last post by:
Hi,
I have a little programm that uses an array of pointers to a structure. Everything works fine until I free up the memory.
Here is the sample code:
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
|
by: =?ISO-8859-1?Q?Nordl=F6w?= |
last post by:
I am currently designing a synchronized queue used to communicate
between threads. Is the code given below a good solution? Am I
using mutex lock/unlock more than needed?
Are there any resources out there on the Internet on how to design
*thread-safe* *efficient* data-
structures?
/Nordlöw
|
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...
|
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,...
| |
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...
|
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,...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |