473,802 Members | 2,253 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
In article <Xn************ *************** @194.125.133.14 >,
Frederick Gotham <fg*******@SPAM .com> wrote:
....
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
clear that my error was more a question of "getting things muddled up"
rather than having a deficit of proficiency. When I myself correct such
silly errors, I am usually more sociable about it -- even one little
comment:

You've got them the wrong way around, should be:
typedef double T;


Since it is the custom around here to post URLs with pointed commentary
about how the OP should read them before asking any more dumb questions,
I offer up the following (which explains a lot about this ng):

http://en.wikipedia.org/wiki/Aspergers

Jun 18 '06 #11
Kenny McCormack posted:

Since it is the custom around here to post URLs with pointed commentary
about how the OP should read them before asking any more dumb questions,
I offer up the following (which explains a lot about this ng):

http://en.wikipedia.org/wiki/Aspergers


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?

--

Frederick Gotham
Jun 18 '06 #12
In article <Xn************ *************** @194.125.133.14 >,
Frederick Gotham <fg*******@SPAM .com> wrote:
Kenny McCormack posted:

Since it is the custom around here to post URLs with pointed commentary
about how the OP should read them before asking any more dumb questions,
I offer up the following (which explains a lot about this ng):

http://en.wikipedia.org/wiki/Aspergers


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?


It has been theorized by many observers of this ng that many of the
so-called "regulars" suffer from some form(s) of the condition, and that
the ng serves as some kind of "support group" for them. It explains a
lot of the quirky responses you see here, and it is helpful to be
familiar with the condition when evaluating posts seen here.

Discussion of the condition itself is, of course, OT here, since there
is no mention of it in any of the C standards documents.

Jun 18 '06 #13
Frederick Gotham <fg*******@SPAM .com> writes:
Kenny McCormack posted: [snip] 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 McCormack is a notorious self-described troll, who unfortunately
seems to have returned after a long and welcome absence. Please
ignore him.

If you don't want to take my word for this (and there's no real reason
why you should), feel free to search Google's archives for his past
"contributi ons" here.

--
Keith Thompson (The_Other_Keit h) ks***@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.
Jun 18 '06 #14
"lovecreatesbea uty" <lo************ ***@gmail.com> writes:
Richard Heathfield wrote:
ln****@yahoo.co m said:
> why sizeof 'a' return 4?

'a' is an int. The size of an int is implementation-dependent. I guess on
your system it's 4, yes?


But you seemed a little hesitant? If it's implementation-dependent, the
following equations are always true. It is true after my test :)

char c = 'c';
sizeof c == 1; /*by definition :)*/
sizeof 'c' == 4;


sizeof 'c' == sizeof(int)

sizeof(int) may or may not be 4.
> (Note the argument is without parenthesis)

Good. No point splashing them everywhere for no reason.


A pair of parentheses is required when type names applied to sizeof
operator. Is it because parentheses occur around type names in type
conventions?


I assume you mean "type conversions" (i.e., cast operators).

The syntax of the sizeof operator is

sizeof unary-expression
sizeof ( type-name )

Conceivably this could have been defined as:

sizeof unary-expression
sizeof type-name

but I think that would have led to ambiguities in some cases.

The parentheses around a type-name in a cast operator and in a sizeof
expression aren't necessarily related to each other. They're defined
separately in distinct parts of the grammar. They were probably added
for similar reasons in both cases (to avoid ambiguity), and for all I
know one might have inspired the other, but as far as the language
definition is concerned they're just two out of many uses of the "("
and ")" symbols.

--
Keith Thompson (The_Other_Keit h) ks***@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.
Jun 18 '06 #15
Frederick Gotham <fg*******@SPAM .com> writes:
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.
Jun 18 '06 #16
Frederick Gotham <fg*******@SPAM .com> writes:
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_Keit h) ks***@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.
Jun 18 '06 #17
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.

Brian
Jun 18 '06 #18
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.

Jun 18 '06 #19
In article <87************ @gmail.com>,
Simon Lewis <si************ @gmail.com> wrote:
....
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.

Jun 18 '06 #20

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
10529
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...
0
10301
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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
10058
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
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...
0
6835
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
5492
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
5620
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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.