473,405 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 1326
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.invalidwrites:
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_Keith) 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.invalidwrites:
>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.invalidwrites:
>>[...]
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.invalidwrote in message
news:64****************@news.aioe.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
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...
3
by: Mary | last post by:
MemberID VID 1002 1001 1003 1002 1004 1003 1005 1003 1007 1001...
5
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...
3
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
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...
1
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...
4
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...
6
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...
0
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,...
0
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...

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.