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

my output

Â*Â*Â*Â*Â*printfÂ*("\nÂ*%uÂ*"Â*,Â*sizeofÂ*(Â*ubÂ*) Â*)Â*;
Â*Â*Â*Â*Â*printfÂ*("\nÂ*%uÂ*"Â*,Â*sizeofÂ*(Â*sbÂ*) Â*)Â*;
Â*Â*Â*Â*Â*printfÂ*("\nÂ*%uÂ*"Â*,Â*sizeofÂ*(Â*nÂ*)Â *)Â*;
Â*Â*Â*Â*Â*printfÂ*("\nÂ*%uÂ*"Â*,Â*sizeofÂ*(Â*char *)Â*)Â*;

Â*Â*Â*Â*Â*ub.cÂ*=Â*'a'Â*;

Â*Â*Â*Â*Â*printfÂ*("\n\nÂ*%cÂ*"Â*,Â*Â*ub.cÂ*)Â*;
Â*Â*Â*Â*Â*printfÂ*("\nÂ*%uÂ*"Â*,Â*Â*ub.a.highÂ*)Â* ;
Â*Â*Â*Â*Â*printfÂ*("\nÂ*%uÂ*"Â*,Â*Â*ub.a.lowÂ*)Â*;

my output :

8
8
4
1

a
97
9515004 [root@localhost home]

************************************************** *

this is my output i have compiled with g++ in fedora core 2

question was : the amount of memory struct snibble use

i thinked struct of bit (snibble) ,
you can see,
get at most 4 bit in memory and not 4 bytes.
struct snibble {
unsigned a : 1 ;
unsigned b : 1 ;
unsigned c : 1 ;
unsigned d : 1 ;
} ;

tomorrow i try disassemble program and see even bits are bits or bytes !?

thx a lot

claudio
Jul 22 '05 #1
2 1411
On Mon, 02 Aug 2004 18:01:24 GMT, Claudio <da************@libero.it>
wrote in comp.lang.c++:
*****printf*("\n*%u*"*,*sizeof*(*ub*)*)*;
*****printf*("\n*%u*"*,*sizeof*(*sb*)*)*;
*****printf*("\n*%u*"*,*sizeof*(*n*)*)*;
*****printf*("\n*%u*"*,*sizeof*(*char*)*)*;

*****ub.c*=*'a'*;

*****printf*("\n\n*%c*"*,**ub.c*)*;
*****printf*("\n*%u*"*,**ub.a.high*)*;
*****printf*("\n*%u*"*,**ub.a.low*)*;

my output :

8
8
4
1

a
97
9515004 [root@localhost home]

************************************************** *

this is my output i have compiled with g++ in fedora core 2

question was : the amount of memory struct snibble use A bit-field structure is an object, and all objects must be at least
one byte in size. If you have an array of these structures, each one
must have its own address, therefore each one must occupy a whole byte
by itself.
i thinked struct of bit (snibble) ,
you can see,
get at most 4 bit in memory and not 4 bytes.
struct snibble {
unsigned a : 1 ;
unsigned b : 1 ;
unsigned c : 1 ;
unsigned d : 1 ;
} ;
Both the C and C++ language standards leave it up to the
implementation (the compiler) to select a type for storing bit-field
structures. It is very common for implementations to use an int or
unsigned int data type for this underlying storage type. On most 32
bit compilers, the size of this bit-field structure will be
sizeof(int), which happens to be 4 on most of these platforms.

Only 4 bits of the 32 bit integer type will actually be used, the rest
will not contain anything useful, but you are confusing the size of
the data with the size of the container.
tomorrow i try disassemble program and see even bits are bits or bytes !?

thx a lot

claudio


--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Jul 22 '05 #2
> printf*("\n*%u*"*,*sizeof*(*ub*)*)*;
printf*("\n*%u*"*,*sizeof*(*sb*)*)*;
printf*("\n*%u*"*,*sizeof*(*n*)*)*;
printf*("\n*%u*"*,*sizeof*(*char*)*)*;

ub.c*=*'a'*;

printf*("\n\n*%c*"*,**ub.c*)*;
printf*("\n*%u*"*,**ub.a.high*)*;
printf*("\n*%u*"*,**ub.a.low*)*;

my output :

8
8
4
1

a
97
9515004 [root@localhost home]

************************************************** *

this is my output i have compiled with g++ in fedora core 2

question was : the amount of memory struct snibble use

i thinked struct of bit (snibble) ,
you can see,
get at most 4 bit in memory and not 4 bytes.
struct snibble {
unsigned a : 1 ;
unsigned b : 1 ;
unsigned c : 1 ;
unsigned d : 1 ;
} ;

tomorrow i try disassemble program and see even bits are bits or bytes !?

thx a lot

claudio


try:
struct highnibble
{
unsigned char unusedh:4;
unsigned char d:1;
unsigned char c:1;
unsigned char b:1;
unsigned char a:1;
}

struct lownibble
{
unsigned char d:1;
unsigned char c:1;
unsigned char b:1;
unsigned char a:1;
unsigned char unusedl:4;
}

so the compiler is informed to use char instead of CPU-dependent int for
your struct.
both gcc/Linux and cl/Microsoft build a struct consuming one byte of memory.
if you make a union of both with char, you can (nearly) do what you want.
see reply on your request
'bitfield & union strange ?!' from the 8th of august.

regards,
godfired
Jul 22 '05 #3

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

Similar topics

4
by: Mark Wilson CPU | last post by:
This must be easy, but I'm missing something... I want to execute a Perl script, and capture ALL its output into a PHP variable. Here are my 2 files: -------------------------------------...
3
by: edgekaos | last post by:
Is method 2 valid? Method 1: wstring input = L"STRING"; wstring output = input; transform(output.begin(), output.end(), output.begin(), towupper); Method 2: wstring input = L"STRING";...
4
by: Kevin Mansel via .NET 247 | last post by:
Ok, basically this is my problem. I'm building a console app tocall a dos program. So i'm using the Shell command to call theprogram, now depending on what happens, I want to read theoutput that...
24
by: kalamantina | last post by:
#include "stdafx.h" #include <stdio.h> #define output( x ) printf( #x "\r\n" );fflush( stdout ) class CMyBase { public: CMyBase() { output( CMyBase() ); f(*this);
0
by: newbie | last post by:
i'm a newbie of c language. can anyone help me to implement the code so that I can get the ciphertext from the output. thanks. #ifndef _3DES_H #define _3DES_H #ifndef uint8 #define uint8 ...
32
by: spibou | last post by:
Is the output of the C preprocessor deterministic ? What I mean by that is , given 2 compilers which conform to the same standard, will their preprocessors produce identical output given as input...
3
by: MatsL | last post by:
Hi, This is seriously driving me crazy, could anyone explain to me why neither of these doesn't produce XHTML compliant output (it is being called in Render() btw): output.WriteLine("<img...
3
by: undshan | last post by:
I am writing a code that needs to open a file, create an output file, run through my function, prints the results to the output file, and closes them within a loop. Here is my code: #include...
5
by: amit.uttam | last post by:
Hey everyone, I've recently jumped big time into python and I'm working on a software program for testing automation. I had a question about proper logging of output. What I would like is: 1....
2
by: gabosom | last post by:
Hi! I've been breaking my head trying to get the output variables from my Stored Procedure. This is my SP code CREATE PROCEDURE GetKitchenOrderDetail( @idService int, --outPut Variables ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.