niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
· nixdoc.net · man pages · Linux HOWTOs · FreeBSD Tips · Forums
navigation Forum index » Programming » C
sizeof 'a' returns 4
Post new topic   Reply to topic Page 2 of 2 [30 Posts] View previous topic :: View next topic
Goto page:  Previous  1, 2
Author Message
Simon Lewis
*nix forums beginner


Joined: 18 Jun 2006
Posts: 1

PostPosted: Sun Jun 18, 2006 8:23 pm    Post subject: Re: sizeof 'a' returns 4 Reply with quote

Frederick Gotham <fgothamNO@SPAM.com> writes:

Quote:
Richard Heathfield posted:

Frederick Gotham said:

posted:

Hello

I've got a simple question regarding sizeof operator.
why sizeof 'a' return 4?
(Note the argument is without parenthesis)

If anybody is so kind to answer ...
TIA


typedef T double;

Syntax error.


So as not to clutter the newsgroup, I would request in future that, if
you choose to scrutanise and correct my code, that you correct the error
rather than simply indicate that an error is present -- it will be of
benefit to us all.


typedef double T;


Another thing, and this is your own perogative of course, maybe you'd
like to be more "social" about how you offer your counsel? It's pretty

Some chance.

Just google up some examples of his "help". Certainly seems to think
he's something special : but all I can see are self grandizing smart ass
comments generally designed to bemuse the newbie. Aspergers is a great
description IMO.
Back to top
Keith Thompson
*nix forums Guru


Joined: 28 Feb 2005
Posts: 5173

PostPosted: Sun Jun 18, 2006 8:37 pm    Post subject: Re: sizeof 'a' returns 4 Reply with quote

Frederick Gotham <fgothamNO@SPAM.com> writes:
Quote:
posted:
I've got a simple question regarding sizeof operator.
why sizeof 'a' return 4?
(Note the argument is without parenthesis)

If anybody is so kind to answer ...
TIA

typedef T double;


unsigned SizeOf( T const t )
{
const char * const current = (const char*)&t;

const char * const next = (const char*)(&t + 1);

return next - current;
}

Was that supposed to be posted to a different thread? It doesn't seem
to have any relationship to the original question (which is question
8.9 of the comp.lang.c FAQ).

--
Keith Thompson (The_Other_Keith) kst-u@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.
Back to top
Default User
*nix forums Guru


Joined: 21 Feb 2005
Posts: 1159

PostPosted: Sun Jun 18, 2006 8:38 pm    Post subject: Re: sizeof 'a' returns 4 Reply with quote

Frederick Gotham wrote:

Quote:
Kenny McCormack posted:

[blither blather]

Quote:
I'm not sure I understand what you're getting as... but are you
suggesting that this newsgroup bears some sort of association with
Asperger Syndrome?


Kenny is a troll, whose intention is disrupt the newsgroup. Just ignore
him. If you use a killfile, he's a good candidate.



Brian
Back to top
Kenny McCormack
*nix forums Guru


Joined: 24 Mar 2005
Posts: 657

PostPosted: Sun Jun 18, 2006 10:41 pm    Post subject: Re: sizeof 'a' returns 4 Reply with quote

In article <4flrtoF1jb96hU1@individual.net>,
Default User <defaultuserbr@yahoo.com> wrote:
Quote:
Frederick Gotham wrote:

Kenny McCormack posted:

[blither blather]

I'm not sure I understand what you're getting as... but are you
suggesting that this newsgroup bears some sort of association with
Asperger Syndrome?


Kenny is a troll, whose intention is disrupt the newsgroup. Just ignore
him. If you use a killfile, he's a good candidate.

Man, you guys must really be worried.

Your responses are sooooo predictable.
Back to top
Kenny McCormack
*nix forums Guru


Joined: 24 Mar 2005
Posts: 657

PostPosted: Sun Jun 18, 2006 10:42 pm    Post subject: Re: sizeof 'a' returns 4 Reply with quote

In article <87irmyp613.fsf@gmail.com>,
Simon Lewis <simonlewis2001@gmail.com> wrote:
....
Quote:
Some chance.

Just google up some examples of his "help". Certainly seems to think
he's something special : but all I can see are self grandizing smart ass
comments generally designed to bemuse the newbie. Aspergers is a great
description IMO.

So true. So true. Welcome to the Light Side.
Back to top
Nelu
*nix forums beginner


Joined: 19 Jun 2006
Posts: 1

PostPosted: Mon Jun 19, 2006 12:00 am    Post subject: Re: sizeof 'a' returns 4 Reply with quote

gazelle@xmission.xmission.com (Kenny McCormack) writes:

Quote:
In article <4flrtoF1jb96hU1@individual.net>,
Default User <defaultuserbr@yahoo.com> wrote:
Frederick Gotham wrote:

Kenny McCormack posted:

[blither blather]

I'm not sure I understand what you're getting as... but are you
suggesting that this newsgroup bears some sort of association with
Asperger Syndrome?


Kenny is a troll, whose intention is disrupt the newsgroup. Just ignore
him. If you use a killfile, he's a good candidate.

Man, you guys must really be worried.

Your responses are sooooo predictable.


Just a general observation: when the teacher repeats the rules he's
only predictable if the pupil learnt them but doesn't give a damn
about them. That makes a brat... a modern time \sout{rock'n'roll}
troll. Some people grow up, eventually.

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)
Back to top
Barry Schwarz
*nix forums Guru


Joined: 09 Apr 2005
Posts: 390

PostPosted: Mon Jun 19, 2006 12:22 am    Post subject: Re: sizeof 'a' returns 4 Reply with quote

On Sun, 18 Jun 2006 13:37:03 GMT, Frederick Gotham
<fgothamNO@SPAM.com> wrote:

Quote:
posted:

Hello

I've got a simple question regarding sizeof operator.
why sizeof 'a' return 4?
(Note the argument is without parenthesis)

If anybody is so kind to answer ...
TIA



typedef T double;


unsigned SizeOf( T const t )
{
const char * const current = (const char*)&t;

const char * const next = (const char*)(&t + 1);

return next - current;
}

Your typedef has a syntax error.

What does the size of a double have to do with the original question?

Did you mean
typedef int T;

If the OP realized that 'a' was of type int (and not char), he
probably wouldn't have asked the question in the first place.


Remove del for email
Back to top
Dik T. Winter
*nix forums Guru


Joined: 23 Feb 2005
Posts: 327

PostPosted: Mon Jun 19, 2006 12:38 am    Post subject: Re: sizeof 'a' returns 4 Reply with quote

In article <87irmyp613.fsf@gmail.com> Simon Lewis <simonlewis2001@gmail.com> writes:
Quote:
Frederick Gotham <fgothamNO@SPAM.com> writes:
Richard Heathfield posted:
Frederick Gotham said:
posted:
....
why sizeof 'a' return 4?
....
typedef T double;

Syntax error.

So as not to clutter the newsgroup, I would request in future that,
....
Some chance.

Just google up some examples of his "help".

Well, if somebody posts a follow-up with completely irrelevant information,
you can expect some comments. I will give full comments:

Quote:
typedef T double;


Interchange 'T' and 'double'

Quote:
unsigned SizeOf( T const t )
{
const char * const current = (const char*)&t;
const char * const next = (const char*)(&t + 1);
return next - current;
}

This does not answer the original question (why sizeof 'a' == 4). I think
it was intended as a response to a question in another thread about a user
replacement of sizeof. And it also fails as that. It returns
sizeof (double). So can Frederick Gotham explain the intent of his
article?
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Back to top
Old Wolf
*nix forums Guru


Joined: 20 Feb 2005
Posts: 679

PostPosted: Mon Jun 19, 2006 1:03 am    Post subject: Re: sizeof 'a' returns 4 Reply with quote

Richard Heathfield wrote:
Quote:
Frederick Gotham said:

typedef T double;

Syntax error.

Interesting (?) fact I encountered while verifying your answer:

typedef double;

is NOT a syntax error; nor is:

double;
Back to top
lovecreatesbeauty
*nix forums Guru Wannabe


Joined: 21 Feb 2005
Posts: 193

PostPosted: Mon Jun 19, 2006 3:17 am    Post subject: Re: sizeof 'a' returns 4 Reply with quote

Old Wolf wrote:
Quote:

Interesting (?) fact I encountered while verifying your answer:

typedef double;

is NOT a syntax error; nor is:

double;

Does following answer the question?

lovecreatesbeauty

/*quoting begins*/
A.2.2 Declarations

(6.7) declaration-specifiers:
storage-class-specifier declaration-specifiers(opt)
type-specifier declaration-specifiers(opt)
<snip>

(6.7.1) storage-class-specifier:
typedef
<snip>

(6.7.2) type-specifier:
<snip>
double
<snip>
/*quoting ends*/
Back to top
Old Wolf
*nix forums Guru


Joined: 20 Feb 2005
Posts: 679

PostPosted: Mon Jun 19, 2006 3:25 am    Post subject: Re: sizeof 'a' returns 4 Reply with quote

lovecreatesbeauty wrote:
Quote:
Old Wolf wrote:

Interesting (?) fact I encountered while verifying your answer:

typedef double;

is NOT a syntax error; nor is:

double;

Does following answer the question?

What question?
Back to top
Harald van D議k
*nix forums Guru Wannabe


Joined: 06 Feb 2006
Posts: 123

PostPosted: Mon Jun 19, 2006 6:27 am    Post subject: Re: sizeof 'a' returns 4 Reply with quote

Old Wolf wrote:
Quote:
Richard Heathfield wrote:
Frederick Gotham said:

typedef T double;

Syntax error.

Interesting (?) fact I encountered while verifying your answer:

typedef double;

is NOT a syntax error; nor is:

double;

Right, it's a constraint violation, and not a syntax error, because a
type-specifier followed by a semicolon can be a valid declaration:

struct S { /* ... */ };

Another interesting fact (? here too):

struct S { /* ... */ } typedef;

is allowed as well, and does not define any variable.
Back to top
neutron*star
*nix forums Guru


Joined: 21 Feb 2005
Posts: 2039

PostPosted: Mon Jun 19, 2006 6:49 am    Post subject: Re: sizeof 'a' returns 4 Reply with quote

Frederick Gotham said:

Quote:
Richard Heathfield posted:

Frederick Gotham said:

posted:

Hello

I've got a simple question regarding sizeof operator.
why sizeof 'a' return 4?
(Note the argument is without parenthesis)

If anybody is so kind to answer ...
TIA


typedef T double;

Syntax error.


So as not to clutter the newsgroup, I would request in future that, if
you choose to scrutanise and correct my code, that you correct the error
rather than simply indicate that an error is present -- it will be of
benefit to us all.

Sorry, Frederick. I thought I had given sufficient information, given the
limited number of ways in which it could be wrong.

Quote:
Another thing, and this is your own perogative of course, maybe you'd
like to be more "social" about how you offer your counsel?

Your original reply was not only an attempt to spoonfeed a homework answer
(always a bad idea) but was also an incorrect answer to the wrong question,
and it would not even compile.

This is your own prerogative, of course, but maybe you'd like to focus on
getting your own house in order before you start telling other people what
to write?

Quote:
It's pretty
clear that my error was more a question of "getting things muddled up"
rather than having a deficit of proficiency.

My comment that your code had a syntax error was not a claim that you had a
"deficit of proficiency". It was a comment that your code had a syntax
error. These are not the same thing. But you can try for "deficit of
proficiency" if you like.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Back to top
Mark McIntyre
*nix forums Guru


Joined: 16 Feb 2005
Posts: 1564

PostPosted: Mon Jun 19, 2006 9:17 pm    Post subject: Re: sizeof 'a' returns 4 Reply with quote

On Sun, 18 Jun 2006 22:23:20 +0200, in comp.lang.c , Simon Lewis
<simonlewis2001@gmail.com> wrote:

Quote:
Just google up some examples of his "help". Certainly seems to think
he's something special : but all I can see are self grandizing smart ass
comments generally designed to bemuse the newbie. Aspergers is a great
description IMO.

Congrats, you get the fsckwit of the week award.
--
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
Back to top
Mark McIntyre
*nix forums Guru


Joined: 16 Feb 2005
Posts: 1564

PostPosted: Mon Jun 19, 2006 9:18 pm    Post subject: Re: sizeof 'a' returns 4 Reply with quote

On Sun, 18 Jun 2006 22:41:39 +0000 (UTC), in comp.lang.c ,
gazelle@xmission.xmission.com (Kenny McCormack) wrote:

Quote:
In article <4flrtoF1jb96hU1@individual.net>,
Default User <defaultuserbr@yahoo.com> wrote:
Frederick Gotham wrote:

Kenny McCormack posted:

[blither blather]

I'm not sure I understand what you're getting as... but are you
suggesting that this newsgroup bears some sort of association with
Asperger Syndrome?


Kenny is a troll, whose intention is disrupt the newsgroup. Just ignore
him. If you use a killfile, he's a good candidate.

Man, you guys must really be worried.

Your responses are sooooo predictable.

*replonk*
--
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
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 2 of 2 [30 Posts] Goto page:  Previous  1, 2
View previous topic :: View next topic
The time now is Thu Sep 09, 2010 11:44 am | All times are GMT
navigation Forum index » Programming » C
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts ConfigParser: what read('non-existent-filename') returns ... Danil Dotsenko python 4 Thu Jul 20, 2006 5:50 pm
No new posts CGI.pm and lost carriage returns Joseph Czapski Perl 21 Thu Jul 20, 2006 3:52 pm
No new posts sizeof() junw2000@gmail.com C++ 6 Wed Jul 19, 2006 3:56 pm
No new posts sizeof() junw2000@gmail.com C 12 Wed Jul 19, 2006 3:51 pm
No new posts "who am i" returns always "localhost" 地球人 AIX 5 Tue Jul 18, 2006 12:36 pm

Copyright © 2004-2005 DeniX Solutions SRL
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum |  email marketing service
 
Sponsors: Breast Enlargement | Nikon D5000 | Breast Enlargement | Project Management Software | Cheap Home Insurance
Privacy Policy
[ Time: 0.0922s ][ Queries: 17 (0.0437s) ][ GZIP on - Debug on ]