PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > c++
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
c++

Réponse
 
LinkBack Outils de la discussion
Vieux 26/12/2007, 13h40   #1
vich
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut c++

hi
1.what will be the size of character pointer
2. what will be the size of a class which do not have private
datamember or member functions?
eg. class k{ };
3. do anybody have any pointers related output questions
  Réponse avec citation
Vieux 26/12/2007, 14h36   #2
Kira Yamato
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: c++

On 2007-12-26 08:40:45 -0500, vich <sundaram.bhuvana@gmail.com> said:

> hi
> 1.what will be the size of character pointer


Have you tried to write a sample program to find out?

> 2. what will be the size of a class which do not have private
> datamember or member functions?
> eg. class k{ };


Same question as above.

> 3. do anybody have any pointers related output questions


Are you preparing for a job interview? Try googling "C++ FAQ".

--

-kira

  Réponse avec citation
Vieux 26/12/2007, 15h01   #3
Dave Rahardja
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: c++

On 2007-12-26 07:40:45 -0600, vich <sundaram.bhuvana@gmail.com> said:

> hi
> 1.what will be the size of character pointer


Implementation defined.

> 2. what will be the size of a class which do not have private
> datamember or member functions?
> eg. class k{ };


Implementation defined.

> 3. do anybody have any pointers related output questions


Not me.

-dr

  Réponse avec citation
Vieux 26/12/2007, 15h02   #4
Ron Natalie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: c++

vich wrote:
> hi
> 1.what will be the size of character pointer

sizeof (char*)

> 2. what will be the size of a class which do not have private
> datamember or member functions?


public/private/protected has NO real bearing on size.

> eg. class k{ };


sizeof(k) is at least one. All objects are at least 1 byte long.
It could be bigger. It depends on your implementation.

> 3. do anybody have any pointers related output questions


Could you rephrase that in English?
  Réponse avec citation
Vieux 26/12/2007, 15h03   #5
Ron Natalie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: c++

Kira Yamato wrote:
> On 2007-12-26 08:40:45 -0500, vich <sundaram.bhuvana@gmail.com> said:
>
>> hi
>> 1.what will be the size of character pointer

>
> Have you tried to write a sample program to find out?


That would tell him for his specific implementation, but it doesn't
give the real answer.

>

  Réponse avec citation
Vieux 26/12/2007, 15h14   #6
Salt_Peter
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: c++

On Dec 26, 8:40 am, vich <sundaram.bhuv...@gmail.com> wrote:
> hi
> 1.what will be the size of character pointer


Depends on the machine. However, nobody cares.
Code should be transparent to the platform / architecture involved (8
bit, 32 bit, 64 bit, etc)

> 2. what will be the size of a class which do not have private
> datamember or member functions?


A class has no size. Its just a blueprint.

> eg. class k{ };
> 3. do anybody have any pointers related output questions


try the faq:
http://www.parashift.com/c++-faq-lit...d-objects.html

  Réponse avec citation
Vieux 26/12/2007, 15h56   #7
Daniel T.
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: c++

vich <sundaram.bhuvana@gmail.com> wrote:

> 1.what will be the size of character pointer


The same size as any other pointer. It's compiler dependent.

> 2. what will be the size of a class which do not have private
> datamember or member functions?
> eg. class k{ };


This is a special case.

class k { };
class y : k { };

'sizeof( k )' probably equals 1, which implies that all 'k' objects are
one byte, however 'sizeof( y )' probably also equals 1, so class 'k'
isn't adding anything to the size of derived objects...

So the answer to this question is that it is compiler and situation
dependent.

> 3. do anybody have any pointers related output questions


I don't understand the question.
  Réponse avec citation
Vieux 28/12/2007, 00h29   #8
Ron Natalie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: c++

Daniel T. wrote:
> vich <sundaram.bhuvana@gmail.com> wrote:
>
>> 1.what will be the size of character pointer

>
> The same size as any other pointer. It's compiler dependent.
>
>> 2. what will be the size of a class which do not have private
>> datamember or member functions?
>> eg. class k{ };

>
> This is a special case.
>
> class k { };
> class y : k { };
>
> 'sizeof( k )' probably equals 1, which implies that all 'k' objects are
> one byte, however 'sizeof( y )' probably also equals 1, so class 'k'
> isn't adding anything to the size of derived objects...
>
> So the answer to this question is that it is compiler and situation
> dependent.
>

The fact that sizeof(y) is also 1 doesn't change the fact that sizeof(k)
is one. It just goes to show that the size of a class is not
necessarily the sum of the sizes of it's subobjects.
  Réponse avec citation
Vieux 01/01/2008, 10h32   #9
James Kanze
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: c++

On Dec 26 2007, 4:02 pm, Ron Natalie <r...@spamcop.net> wrote:
> vich wrote:
> > 2. what will be the size of a class which do not have private
> > datamember or member functions?


> public/private/protected has NO real bearing on size.


Unless the implementation decides otherwise. I don't know of
any which do, but I could very easily imagine an implementation
where:

class C1
{
public:
double d1 ;
char c1 ;
double d2 ;
char c2 ;
} ;

class C2
{
public:
double d1 ;
private:
char c1 ;
public:
double d2 ;
private:
char c2 ;
} ;

and sizeof( C1 ) == 32 but sizeof( C2 ) == 24. An
implementation is allowed to rearrange the order of variables if
there is an intervening access specifier.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

  Réponse avec citation
Vieux 01/01/2008, 10h38   #10
James Kanze
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: c++

On Dec 26 2007, 4:56 pm, "Daniel T." <danie...@earthlink.net> wrote:
> vich <sundaram.bhuv...@gmail.com> wrote:
> > 1.what will be the size of character pointer


> The same size as any other pointer. It's compiler dependent.


It's implementation dependent, but all pointers aren't
necessarily the same size. I've used machines where char* (and
void*, if void had existed back then) was larger than int*, and
on one of the most wide spread machines some years ago, function
pointers could have a different size than data pointers. (Back
when I last worked on a portable compiler, we considered four
different sizes for pointers: char pointers, other data
pointers, function pointers and label pointers---you can't
declare anything with the last type in C/C++, but they were used
by Fortran, and internally in the code generated for a switch.)

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 17h38.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,18574 seconds with 18 queries