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

once aand for aall

Can somebody answer me this..

1)

when am I guaranteed the size in bytes of primitive types? Can I
always assume a char is one byte? can I always assume that my float is
4 bytes? likewise for longs, unsigned longs etc. What are the hard and
fast rules?
2)

also, in the following code, when an instace of derived has been
created, why exactly is the function F not ambiguous?
class base
{
public:

virtual int f(int) { };
};

class derived : public base
{
public:

derived()
{
f(0);
};

int f(char* s) { };
};
3)
is this legal? It all appears on the same line.

#define ABS(a) (a) <0 ? -(a):(a) #define GTR(b) (b)>9? (1) : (0)
4)

lastly, if I have

int matrix[][2] = { {1}, {2} };
can somebody tell me exactly whats initialised to what and why the []
is legal. What exactly have I declared and initialised above?

thanks much for your help.
GrahamO
Jul 22 '05 #1
2 1224
On 25 Feb 2004 16:58:30 -0800 in comp.lang.c++,
gr************@hotmail.com (grahamo) was alleged to have written:

when am I guaranteed the size in bytes of primitive types?
Almost never. There are some minimum constraints, but no exact size
guarantees.
Can I always assume a char is one byte?
Yes. "char" and "byte" are used interchangeably.

Very important: "char" and "byte" DOES NOT have to be exactly 8 bits.
It must be at least 8 bits, but can be more, like e.g. 9 or 16.

The constant CHAR_BITS defined in <limits.h> tells you how many bits in
a byte in your particular implementation of C++.

The sizeof() operator tells you how many CHAR_BITS units other types are
in your particular implementation of C++.

Also, there are lots of other interesting numbers defined in <limits>
that you may wish to look at.
can I always assume that my float is 4 bytes?
No. float could easily be 1 byte on a machine with 32-bit bytes.
likewise for longs, unsigned longs etc. What are the hard and
fast rules?
long must be at least 32 bits. Could be more.
int must be at least 16 bits. Could be more.
char must be at least 8 bits. Could be more.
etc.

If the smallest physically addressable unit of storage on your machine
is 32 bits, then char, int, and long could possibly all be the same
size.
2)

also, in the following code, when an instace of derived has been
created, why exactly is the function F not ambiguous?


This issue is covered in Marshall Cline's C++ FAQ. See the topic
"[23.6] What's the meaning of, Warning: Derived::f(float) hides
Base::f(int)?" It is always good to check the FAQ before posting. You
can get the FAQ at:
http://www.parashift.com/c++-faq-lite/

Jul 22 '05 #2

"grahamo" <gr************@hotmail.com> wrote in message
news:79**************************@posting.google.c om...
Can somebody answer me this..
You have already got anwers to your first two questions.
3)
is this legal? It all appears on the same line.

#define ABS(a) (a) <0 ? -(a):(a) #define GTR(b) (b)>9? (1) : (0)
Doesn't seem valid code to me.
Instead if the macros are on different lines then it should be fine.

4)

lastly, if I have

int matrix[][2] = { {1}, {2} };
can somebody tell me exactly whats initialised to what and why the []
is legal. What exactly have I declared and initialised above?


[] is legal because compiler is smart enough to find the number of rows in such
initializations.
You have declared an array with 2 rows and 2 columns.
Here matrix[0][0] = 1
matrix[0][1]=0
matrix[1][0]=2
matrix[1][1]=0

Note that in -
int i[10] ={2} only i[0] has a value of 2, all others are 0.

-Sharad
Jul 22 '05 #3

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

Similar topics

1
by: Stuart A Yeates | last post by:
I'm trying to write a template that matches "*" but which has an if clause which if only executed once per type of element seen (where all elements of a type have the same name and namespace). The...
1
by: Jacob Jensen | last post by:
Hi I have a problem creating C++ code that is multiplatform compilable. My problem is using the "#pragma once" directive which can be used by microsoft Visual Studio pre-compiler but which gives...
2
by: Just Me | last post by:
When a document is to be printed I call a method that contains an AddHandler statement. I just realized that if a second copy is to be printed the method is called and the AddHandler is executed...
5
by: ShaunO | last post by:
BACKGROUND I have the following classes as part of a program that opens 3 Asynchronous Sockets. Each socket is in a separate instance of a wrapping class. 1x User Interface class 1x Client...
0
by: Mark | last post by:
Hi, We are a software company that wish to use Click-Once deployment to allow our customers to deliver smart clients to their worker's desktops. We have experimented successfully in-house...
5
by: =?Utf-8?B?UmljaA==?= | last post by:
Greetings, I have been using the Click Once deployment feature of VS2005 - very nice. I had IE6 at the time when I started using Click Once Deployment, and everything worked fine. But then my...
3
by: Eric Layman | last post by:
Hi, If an E-coupon is limited to one person, are there ways to prevent it from printing more than once? Since on the print dialog, user can print multiple copies. Regards
3
by: Joey Nolan | last post by:
Hi, I have a PDF file on my site that I want to distribute freely but I want to be able to contact anyone who downloaded it to warn them about mistakes and new versions and updates etc... So I...
29
by: Neil | last post by:
Running a SQL 7 system on a Windows 2000 server using Access 2000 on client machines as a front end. System administrator currently reboots the server once a month. Yesterday we had some weird...
26
by: Rick | last post by:
I'm told that "#pragma once" has made it into the ISO standard for either C or C++. I can't find any reference to that anywhere. If it's true, do any of you have a reference I can use? ...
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: 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...
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...
0
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,...
0
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...
0
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,...
0
jinu1996
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...

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.