473,698 Members | 2,322 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

is order urgent doubt

Hi!

I write the 2 codes

int i;
i = sizeof(long int);
printf("%i", i);

i = sizeof(int long);
printf("%i", i);

and the first code and second code print 4.

I write another 2 codes

i = sizeof(double int);
printf("%i", i);

i = sizeof(int double);
printf("%i", i);

and the first code print 4 and the second code print 8.

My doubt is why is different number? Is order urgent?

May 31 '08 #1
7 1364
new to c wrote:
Hi!

I write the 2 codes

int i;
i = sizeof(long int);
printf("%i", i);

i = sizeof(int long);
printf("%i", i);

and the first code and second code print 4.

I write another 2 codes

i = sizeof(double int);
printf("%i", i);

i = sizeof(int double);
printf("%i", i);

and the first code print 4 and the second code print 8.
I'm surprised you got any output at all, because neither
`double int' nor `int double' is a valid type name. You
should have received error messages from the compiler.
My doubt is why is different number? Is order urgent?
Not in C, but your compiler seems to be processing some
other language.

--
Eric Sosman
es*****@ieee-dot-org.invalid
May 31 '08 #2
new to c <no*@spam.inval idwrites:
I write the 2 codes

int i;
i = sizeof(long int);
printf("%i", i);

i = sizeof(int long);
printf("%i", i);

and the first code and second code print 4.
Right. It won't necessarily be 4 on all systems, but both are
equivalent.

However, "int long" is very non-idiomatic. The compiler can handle it
with no problem, but human readers are going to stumble over it.

(Please ignore the long flame war that will now begin claiming that
anyone who knows C should be able to read "int long" without any
trouble. The fact that the C standard allows variations in the order
of the keywords is fairly obscure; a member of the standard committee
recently posted here saying he didn't even know about it.)
I write another 2 codes

i = sizeof(double int);
printf("%i", i);

i = sizeof(int double);
printf("%i", i);

and the first code print 4 and the second code print 8.
That's surprising. Your compiler should have rejected it, or at least
warned you about it. Are you sure that's *exactly* what you wrote?

[...]

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
May 31 '08 #3
Keith Thompson said:

<snip>
(Please ignore the long flame war that will now begin claiming that
anyone who knows C should be able to read "int long" without any
trouble.
Well, really, Keith, they *should*. I suppose I differ from the "char
unsigned" camp in that I think that writing "char unsigned" rather than
"unsigned char" is bone-headedly dense and ludicrously unfriendly, but
that doesn't give C programmers an excuse not to know that it's possible -
or at least not to be able to find out quickly that it's possible and
legal, the first time they encounter it, which is admittedly "never" for
most C programmers.
The fact that the C standard allows variations in the order
of the keywords is fairly obscure; a member of the standard committee
recently posted here saying he didn't even know about it.)
I think that says more about the member than it does about the language.

<snip>

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 1 '08 #4
Eric Sosman wrote:
>new to c wrote:
>Hi!

I write the 2 codes

int i;
i = sizeof(long int);
printf("%i", i);

i = sizeof(int long);
printf("%i", i);

and the first code and second code print 4.

I write another 2 codes

i = sizeof(double int);
printf("%i", i);

i = sizeof(int double);
printf("%i", i);

and the first code print 4 and the second code print 8.

I'm surprised you got any output at all, because neither
`double int' nor `int double' is a valid type name. You
should have received error messages from the compiler.
>My doubt is why is different number? Is order urgent?

Not in C, but your compiler seems to be processing some
other language.
It appears to be pseudo legal in <unnamed compiler>.

In case OP is using said compiler, here are some quick observations --

(1) if `signed' and `unsigned' appear in the same declaration, only
the last one specified affects signedness.

[Based on earlier observations, <unnamed compileraccepts
`signed main()' but rejects `unsigned main()'. Tests show that
`unsigned signed main()' is accepted but `signed unsigned main()'
is not, from that we can conclude that later modifiers affecting
signedness probably overrule earlier ones.]
(2) if more than one base type appears in a declaration, sometimes,
later conflicting types overrule earlier ones.

[The test method here uses the fact that doing something illegal
(assignment to object of incompatible type) produces a diagnostic
that reveals the actual type of the created object. Consider this
code snippet

void *foo;
double int bar; /* line 5 */
int double baz; /* line 6 */
foo = bar; /* line 7 */
foo = baz; /* line 8 */

5: W: multiple use of 'int'
6: W: multiple use of 'double'
7: E: operands of = have illegal types 'pointer to void' and 'int'
8: E: operands of = have illegal types 'pointer to void' and 'double'

From that we can conclude that `bar' probably has type `int' and
`baz' probaby has type `double'.

Using the same procedure it turns out that `long long double' is
seen as plain `double', but `long double int' is `long int'.
`long short' is `short' and `short long' is `long', `long short long'
is `long' and `short long short' is `short' -- the same rules
affecting signedness discovered in (1) probably also apply when
deciding short or longness.

There is, however, a small inconsistency in that `short short short'
is probably `short' but `long long long' is in category (3)]
(3) other combinations are flagged as errors and compilation stops --

[Same method used as before

void *foo;
unsigned double bar; /* line 5 */
double unsigned baz; /* line 6 */
foo = bar; /* line 7 */
foo = baz; /* line 8 */

5: E: invalid type specification
6: E: invalid type specification
In conclusion, <unnamed compilertreats some illegal combinations
of types/types and types/modifiers as errors, others merely as
warnings; but they are warned about even without any flags
requesting extra warnings and <unnamed compilerappears to be
conforming in these regards.

Answering the original question, `double int' is not a valid
type, but some implementations , in certain cases, appear to pick
one type if more than one is given. In <unnamed compiler>,

`double int' is seen as `int',

and

`int double' is seen as `double',

in both cases after issuing the required diagnostic (warning).

--
T.Pot.

Jun 1 '08 #5
Keith Thompson wrote:
new to c <no*@spam.inval idwrites:
>I write the 2 codes

int i;
i = sizeof(long int);
printf("%i", i);

i = sizeof(int long);
printf("%i", i);

and the first code and second code print 4.

Right. It won't necessarily be 4 on all systems, but both are
equivalent.

However, "int long" is very non-idiomatic. The compiler can handle it
with no problem, but human readers are going to stumble over it.

(Please ignore the long flame war that will now begin claiming that
anyone who knows C should be able to read "int long" without any
trouble. The fact that the C standard allows variations in the order
of the keywords is fairly obscure; a member of the standard committee
recently posted here saying he didn't even know about it.)
>I write another 2 codes

i = sizeof(double int);
printf("%i", i);

i = sizeof(int double);
printf("%i", i);

and the first code print 4 and the second code print 8.

That's surprising. Your compiler should have rejected it, or at least
warned you about it. Are you sure that's *exactly* what you wrote?
He warn "multiple use of int" on first code and "multiple use of double"
on second code but I think is bogus......only one int in first code and
only one double in second code.

I write big international program and need double integer. Why size is
different when other order?

Jun 1 '08 #6
new to c wrote:
Keith Thompson wrote:
>new to c <no*@spam.inval idwrites:
>>[...]
I write another 2 codes

i = sizeof(double int);
printf("%i" , i);

i = sizeof(int double);
printf("%i" , i);

and the first code print 4 and the second code print 8.
That's surprising. Your compiler should have rejected it, or at least
warned you about it. Are you sure that's *exactly* what you wrote?

He warn "multiple use of int" on first code and "multiple use of double"
on second code but I think is bogus......only one int in first code and
only one double in second code.
The wording of the diagnostic message may be misleading,
but that's something you should learn to expect when dealing
with computers. You should start by reading the message and
trying to understand its complaint. If it seems to make no
sense, re-interpret it as meaning "Something is wrong here, but
I can't describe it." If even that seems to make no sense,
read it as "Something is wrong somewhere, maybe not close to
the spot the message complains about."
I write big international program and need double integer. Why size is
different when other order?
There is no such thing as a `double int' or `int double'
in C. Why do you believe you need a "double integer," that
is, what do you hope a "double integer" variable will do
for your program? What are the characteristics of the "double
integer" you think you need? Perhaps there is some actual C
type that will suit your purpose.

--
Eric Sosman
es*****@ieee-dot-org.invalid
Jun 1 '08 #7

"new to c" <no*@spam.inval idwrote in message
news:64******** ********@news.a ioe.org...

I write big international program and need double integer. Why size is
different when other order?
Try: long long int

If you're lucky, this will have size 8.

In C, 'double' is just a bigger version of 'float'

--
Bartc
Jun 1 '08 #8

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

Similar topics

39
2918
by: Nicolas Fleury | last post by:
In the following example: class MyMetaclass(type): pass class MyBaseType(object): __metaclass__ = MyMetaclass class MyType(MyBaseType): x = 4 y = 5 z = 6 Is there any way to modify MyMetaclass to keep the order of x,y,z somewhere?
3
2591
by: Mary | last post by:
MemberID VID 1002 1001 1003 1002 1004 1003 1005 1003 1007 1001 1012 1002 <% MemberList = "1001, 1003, 1002"
5
2305
by: meenu_susi | last post by:
doubt regarding select box....urgent in the below code i am getting data from database..according to the condition.. i want the available data in database to get displayed in selectbox.. for ex... in the code i am getting color=rs("color")according to the condtion if(shirt=name) if i get red, blue as result the i want these two colors to be in selectbox.. if its three colors means i want those three colors to get displayed in...
3
1124
by: reachnaveenkumar | last post by:
Hi, Can any one give me code to find out the height and width of a textbox in Javascript? Its very urgent. Thank you, regards Naveen
0
1128
by: reachnaveenkumar | last post by:
Hi there! Do we have editable combo box in JSF? If so I need an editable combo box in which I can add, edit delete a record. If I type starting letters of a name, then it should list all the names starting with that letter. If we keep on typing the name to half, if match found it should be selected. I need to use this component in my porject. Its urgent. Can any one halp me please? Thank You Regards Naveen
1
1259
by: lckarthikeyan | last post by:
I Have one doubt in parsing function in c... In my program i am using one object identifier like this 1.3.6.7.184 now i want to change like this using parsing function 1_3_6_10_184.. any idea..pleas elet me know..this is very urgent OS:LINUX(CENT OS 4.3) LANGUAGE (C)
4
1259
by: prakashsurya | last post by:
Hello Gud evening I am having a small doubt on window.opener Actually when we use window.opener by default a window will opens with a name local host on the top of window when we press this the tool bar like back,refresh will be displayed actually what i want to know is can we block this one? and if possible how can we? Hope u will help me. Its a bit urgent thanq
6
5473
by: xhe | last post by:
I am using ffmpeg to convert video, this is a sample script: $str='/home/transla1/bin/ffmpeg -i /home/transla1/public_html/ cybertube/web/uploads/video/31_AK000005.AVI -s 240x180 -b 100k -ar 22050 -y /home/transla1/public_html/cybertube/web/uploads/video/ generated/31_70_AK000005.AVI.flv '; //exec($str); runExternal($str,$code); echo $code ;
0
8676
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
9164
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
8870
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
5860
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
4370
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
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3051
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
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2006
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.