473,802 Members | 2,319 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sizeof 'a' returns 4

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

Jun 18 '06
29 2704
ga*****@xmissio n.xmission.com (Kenny McCormack) writes:
In article <4f************ *@individual.ne t>,
Default User <de***********@ 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'ro ll}
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...)
Jun 18 '06 #21
On Sun, 18 Jun 2006 13:37:03 GMT, Frederick Gotham
<fg*******@SPAM .com> wrote:
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
Jun 19 '06 #22
In article <87************ @gmail.com> Simon Lewis <si************ @gmail.com> writes:
Frederick Gotham <fg*******@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:
typedef T double;

Interchange 'T' and 'double'
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/
Jun 19 '06 #23
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;

Jun 19 '06 #24

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?

lovecreatesbeau ty

/*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*/

Jun 19 '06 #25
lovecreatesbeau ty wrote:
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?

Jun 19 '06 #26
Old Wolf wrote:
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.

Jun 19 '06 #27
Frederick Gotham said:
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.
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?
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)
Jun 19 '06 #28
On Sun, 18 Jun 2006 22:23:20 +0200, in comp.lang.c , Simon Lewis
<si************ @gmail.com> wrote:
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
Jun 19 '06 #29
On Sun, 18 Jun 2006 22:41:39 +0000 (UTC), in comp.lang.c ,
ga*****@xmissio n.xmission.com (Kenny McCormack) wrote:
In article <4f************ *@individual.ne t>,
Default User <de***********@ 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
Jun 19 '06 #30

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

Similar topics

3
3672
by: Charlie | last post by:
My Google Groups search on this one showed the endless debates and I did my best to look through them to see if my question was answered and didn't find it. So, here it goes.... From the GG search, I have pretty much gathered and understand why using sizeof(pointer to char) returns 4 in my program. Is there a way to get it to return the actual amount of characters? the basic idea is that I am initializing a char and passing it into a...
12
13592
by: jl_post | last post by:
Dear C++ community, I have a question regarding the size of C++ std::strings. Basically, I compiled the following code under two different compilers: std::string someString = "Hello, world!"; int size1 = sizeof(std::string); int size2 = sizeof(someString); and printed out the values of size1 and size2. size1 and size2 always
2
4272
by: Ronald A. Andersen | last post by:
********** header **************** struct articleFile2 { char CR; int intStampDate; }; *********** source *************** struct articleFile2 *ptrArticle2 = NULL;
83
15637
by: rahul8143 | last post by:
hello, what is difference between sizeof("abcd") and strlen("abcd")? why both functions gives different output when applied to same string "abcd". I tried following example for that. #include <stdio.h> #include <string.h> void main() { char *str1="abcd";
11
2175
by: Ben C | last post by:
Why does this compile with no warnings, what, if anything, does it mean, and why does the program print out 1? #include <stdio.h> int main(void) { printf("%d\n", sizeof(int())); return 0; }
90
8501
by: pnreddy1976 | last post by:
Hi, How can we write a function, which functionality is similar to sizeof function any one send me source code Reddy
40
3667
by: Spiros Bousbouras | last post by:
Do you have an example of an implementation where sizeof(short int) does not divide sizeof(int) or sizeof(int) does not divide sizeof(long int) or sizeof(long int) does not divide sizeof(long long int) ? Same question for the corresponding unsigned types.
1
2317
by: svlsr2000 | last post by:
Here is a small program which i saw a couple of years ago. #include<stdio.h> int main() { char x; if(sizeof(int)==sizeof('a')) printf("\n C compiler\n"); else
15
1540
by: somenath | last post by:
Hi All, I am not able to understand the behavior of the bellow mentioned program. #include<stdio.h> int main(void) { printf("\n Size = %d \n",sizeof 1<0); return 0;
7
1973
by: Yen Kwoon | last post by:
Note: This problem is related to gcc but after some back and forth in group gnu.gcc.help it seems to have morph into more of a c++ specificiation question, hence the transplanting to this group. The original post at gnu.gcc.help can be found at this link http://groups.google.com/group/gnu.gcc.help/browse_thread/thread/ece55cbbd9c36270/2148a6c1ac6119e1?lnk=st&q=#2148a6c1ac6119e1 Here's the question: class base {
0
9699
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
9559
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,...
1
10280
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
9107
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7596
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5620
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4268
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3788
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2964
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.