473,396 Members | 1,970 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,396 software developers and data experts.

Implicit and explicit conversion

Explicit conversion is made by mean of a cast
i.e.

float a;
int b;
....
b = (int) a;

But the implicit conversion? What is?
Nov 14 '05 #1
3 5481
"/* frank */" <__*******@despammed.com> wrote in message
news:2k************@uni-berlin.de...
Explicit conversion is made by mean of a cast
i.e.

float a;
int b;
...
I'll assume that 'a' and 'b' have been initialized
with or assigned values.
b = (int) a;

But the implicit conversion? What is?


Without a cast.

================================================== ===========
ISO/IEC 9899:1999 (E)

6.3 Conversions

1 Several operators convert operand values from one type to
another automatically. This subclause specifies the result
required from such an implicit conversion, as well as those
that result from a cast operation (an explicit conversion).
The list in 6.3.1.8 summarizes the conversions performed by
most ordinary operators; it is supplemented as required by
the discussion of each operator in 6.5.

2 Conversion of an operand value to a compatible type causes
no change to the value or the representation.
================================================== ===========
/* implicit conversions (using your definitions above): */

b = a;
a = b;

-Mike
Nov 14 '05 #2
/* frank */ wrote:
Explicit conversion is made by mean of a cast
i.e.

float a;
int b;
...
b = (int) a;

But the implicit conversion? What is?


Are you ready?
b = a;
Hard, ain't it?
Nov 14 '05 #3
In <2k************@uni-berlin.de> /* frank */ <__*******@despammed.com> writes:
Explicit conversion is made by mean of a cast
i.e.

float a;
int b;
...
b = (int) a;

But the implicit conversion? What is?


Exactly what the name says: a conversion performed by the compiler
automatically (without requiring a cast).

Examples: the integral promotions, the usual arithmetic conversions,
the default argument promotions, calling a function with a prototype
declaration in scope, when the types in the function call don't
match the types in the function declaration, the return statement,
the assignment operator.

Examples (using your declarations above):

b = a + 1; /* two examples in this statement */
printf("%f\n", a);
fseek(fp, 0, SEEK_SET);
int main() { return 0.0; }

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #4

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

Similar topics

11
by: Steve Gough | last post by:
Could anyone please help me to understand what is happening here? The commented line produces an error, which is what I expected given that there is no conversion defined from type double to type...
9
by: Girish | last post by:
Im trying to understand implicit type conversions from object -> string and vice versa. I have two classes, one Driver and one called StringWrapper. These are just test classes that try and...
36
by: Chad Z. Hower aka Kudzu | last post by:
I have an implicit conversion set up in an assembly from a Stream to something else. In C#, it works. In VB it does not. Does VB support implicit conversions? And if so any idea why it would work...
10
by: Pieter Breed | last post by:
Hi All, Please excuse me, but the bulk of my post will be a code post. It describes some weirdness with regards to the implicit casting operator. The crux of the problem is this: I want to...
17
by: arindam.mukerjee | last post by:
I was running code like: #include <stdio.h> int main() { printf("%f\n", 9/5); return 0; }
12
by: robert bristow-johnson | last post by:
presently using linux gcc: $ gcc -v Using built-in specs. Target: i386-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man -- infodir=/usr/share/info...
3
by: Jess | last post by:
Hello, I can perform implicit conversion through constructor, like class A{ public: A(int x):a(x){}; int a; };
3
by: utab | last post by:
Dear all, I was trying to write a more complex program, and while searching for sth in my reference C++ primer, by Lippman. I had a question in the mind, see the code below #include <string>...
8
by: jonpb | last post by:
Hi, Is it possible to define a implicit operator from base to derived types in C#? I have a Point class and would like to derive a Vector class from it and add a couple new vector related...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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...

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.