473,587 Members | 2,479 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

my output

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

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

Â*Â*Â*Â*Â*print fÂ*("\n\nÂ*%cÂ* "Â*,Â*Â*ub.cÂ*) Â*;
Â*Â*Â*Â*Â*print fÂ*("\nÂ*%uÂ*"Â *,Â*Â*ub.a.high Â*)Â*;
Â*Â*Â*Â*Â*print fÂ*("\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 1433
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.l earn.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*(*ch ar*)*)*;

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
8128
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: ------------------------------------- test3.pl ------------------------------------- print "PERL Hello from Perl! (plain print)<br>\n"; print STDERR "PERL This is text sent to STDERR<br>\n"; $output="PERL Some output:<br>\n"; for ($i=0; $i<5; $i++) {
3
2778
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"; wstring output;
4
15058
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 this program returns. I'm just missing the stepshere. I know that I can set the Shell command to an integer,but this only returns a 0 to me telling me that it executed, notwhat is being returned to the console by that application. Isthere a way to...
24
2680
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
2059
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 unsigned char #endif
32
2762
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 the same file ? If not then how much variation is allowed ? Is it just a bit more or less white space here and there or could could there be larger differences ? If the output is not deterministic then is it possible that the output of the...
3
2615
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 src=\"" + vars + " />"); output.AddAttribute(HtmlTextWriterAttribute.Src, (string)vars); output.RenderBeginTag(HtmlTextWriterTag.Img);
3
4651
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 <stdlib.h> #include <stdio.h> #include <math.h> #include <string.h> #include "util.h" //Main Loop
5
3319
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. a function syslog (to log output to log file only) 2. a function stdout (to log output to stdout only) 3. a function sslog (to log output to both log and stdout)
2
3369
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 @idUser int OUTPUT,
0
7923
marktang
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...
0
7852
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,...
0
8216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7974
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,...
0
8221
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5395
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();...
0
3845
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...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1192
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.