473,770 Members | 5,880 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

implicit type conversions

Let me see if I got this :)
1. I know the rules for type conversions in arithmetic expressions
2. I know that an implicit type conversion is done at assignment, so
float x = 1.23;
int t = (int) x;
is equivalent to
int t = x;
(could the latter produce a warning on some complier?)
3. I know that implicit conversions take place with function arguments, but
am a bit shaky here. I suppose that passing a char to a function accepting
int or long will always work, and those sort of conversions seem to make
sense. But what sort of things won't work here? For example, the FAQ says
that the NULL pointer *must* be cast to the appropriate type when sent to a
function as an argument (so, for example, time(NULL) is incorrect, and
time( (time_t *) NULL) is correct?), which seems to indicate that
conversions from (void *) to (some_type *) in function argument lists need
not be (isn't) implicit. If someone would clarify this, I'd be most grateful
(like which sort of things cause warnings, which need be cast and the like).

Thank you.
Nov 14 '05
15 2299
Old Wolf wrote:
void put_strings(cha r *f1, ...)

If called with: put_strings("fo o", NULL); would cause UB even if
NULL is (void *)0.


Not in this case (pointers to void and `a character type' (normally
read as `all the character types') have identical representations ),
but it's certainly a concern for pointers to other types, functions
in particular.

--
++acr@,ka"
Nov 14 '05 #11
In <sl************ ****@ID-227112.user.uni-berlin.de> Sam Dennis <sa*@malfunctio n.screaming.net > writes:
Old Wolf wrote:
void put_strings(cha r *f1, ...)

If called with: put_strings("fo o", NULL); would cause UB even if
NULL is (void *)0.


Not in this case (pointers to void and `a character type' (normally
read as `all the character types') have identical representations ),


Identical representation means exactly zilch in context. What you
need is identical argument passing mechanisms and the standard provides
no normative guarantees about that.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #12
Dan Pop wrote:
In <sl************ ****@ID-227112.user.uni-berlin.de> Sam Dennis <sa*@malfunctio n.screaming.net > writes:
Old Wolf wrote:
void put_strings(cha r *f1, ...)

If called with: put_strings("fo o", NULL); would cause UB even if
NULL is (void *)0.


Not in this case (pointers to void and `a character type' (normally
read as `all the character types') have identical representations ),


What you need is identical argument passing mechanisms and the
standard provides no normative guarantees about that.


That's probably true, but I doubt that there's any conforming
implementation in existence that does not follow the footnote
strongly suggesting this reading.

--
++acr@,ka"
Nov 14 '05 #13
In <sl************ ****@ID-227112.user.uni-berlin.de> Sam Dennis <sa*@malfunctio n.screaming.net > writes:
Dan Pop wrote:
In <sl************ ****@ID-227112.user.uni-berlin.de> Sam Dennis <sa*@malfunctio n.screaming.net > writes:
Old Wolf wrote:
void put_strings(cha r *f1, ...)

If called with: put_strings("fo o", NULL); would cause UB even if
NULL is (void *)0.

Not in this case (pointers to void and `a character type' (normally
read as `all the character types') have identical representations ),


What you need is identical argument passing mechanisms and the
standard provides no normative guarantees about that.


That's probably true, but I doubt that there's any conforming
implementati on in existence that does not follow the footnote
strongly suggesting this reading.


Are they still maintaining the DS9k?

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #14
On 4 Jun 2004 10:37:28 GMT, Da*****@cern.ch (Dan Pop) wrote:
In <sl************ ****@ID-227112.user.uni-berlin.de> Sam Dennis <sa*@malfunctio n.screaming.net > writes:
Old Wolf wrote:
void put_strings(cha r *f1, ...)
[ and using va_arg to get as char* ]
If called with: put_strings("fo o", NULL); would cause UB even if
NULL is (void *)0.


Not in this case (pointers to void and `a character type' (normally
read as `all the character types') have identical representations ),


Identical representation means exactly zilch in context. What you
need is identical argument passing mechanisms and the standard provides
no normative guarantees about that.

It does in C99: 7.5.1.1p2 for va_arg, and 6.5.2.2p6 for (wholly)
unprototyped/K&R1 definitions. Also for (the shared range of)
corresponding signed and unsigned integers. Presumably if any
implementor wasn't already doing these and wasn't willing to change
they would have objected.

- David.Thompson1 at worldnet.att.ne t
Nov 14 '05 #15
In <5a************ *************** *****@4ax.com> Dave Thompson <da************ *@worldnet.att. net> writes:
On 4 Jun 2004 10:37:28 GMT, Da*****@cern.ch (Dan Pop) wrote:
In <sl************ ****@ID-227112.user.uni-berlin.de> Sam Dennis <sa*@malfunctio n.screaming.net > writes:
>Old Wolf wrote:
>> void put_strings(cha r *f1, ...)
>> [ and using va_arg to get as char* ]
>> If called with: put_strings("fo o", NULL); would cause UB even if
>> NULL is (void *)0.
>
>Not in this case (pointers to void and `a character type' (normally
>read as `all the character types') have identical representations ),


Identical representation means exactly zilch in context. What you
need is identical argument passing mechanisms and the standard provides
no normative guarantees about that.

It does in C99: 7.5.1.1p2 for va_arg, and 6.5.2.2p6 for (wholly)
unprototyped/K&R1 definitions. Also for (the shared range of)
correspondin g signed and unsigned integers. Presumably if any
implementor wasn't already doing these and wasn't willing to change
they would have objected.


This is correct, if you fix the va_arg reference. I had the printf case
in mind, where 7.15.1.1p2 doesn't apply.

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

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

Similar topics

3
2618
by: Reneé | last post by:
I wanted to know the order of implicit conversions and which sort of values allow them. From searching around in books and the archive of this mailing list, it seems to be that only numbers are implicitly converted within each other and bools can be implicitly converted to ints? However, I'm unable to find any other implicit conversions and the order of the implicit conversions (something like int->float->long). Any help would be greatly...
9
8516
by: Simon | last post by:
Hi All, Is it possible to disallow implicit casting for an operand of a function written in C? i.e. void foo(int a) {..} short b; foo(b) // error without explicit cast
11
7622
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 Test. I expected the same error from the following line, but it compiles fine. The double is silently truncated to an int and then fed in to the implicit conversion operator. Why does this happen? Is there any way that I can keep the implicit...
9
2085
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 emulate the pattern im trying to follow in an existing project. These are my steps: 1) I have a method "printMe" existing in the application which originally used to take in a string. This method is static and sits in the Driver
11
12795
by: Aaron Queenan | last post by:
Given the classes: class Class { public static implicit operator int(Class c) { return 0; } } class Holder
36
3636
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 in a C# program but not VB? -- Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/ "Programming is an art form that fights back"
17
2517
by: arindam.mukerjee | last post by:
I was running code like: #include <stdio.h> int main() { printf("%f\n", 9/5); return 0; }
82
4635
by: robert bristow-johnson | last post by:
here is a post i put out (using Google Groups) that got dropped by google: i am using gcc as so: $ gcc -v Using built-in specs. Target: i386-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man -- infodir=/usr/share/info --enable-shared --enable-threads=posix -- enable-checking=release --with-system-zlib --enable-__cxa_atexit --
8
5669
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 functions, like Normalize(). The problem is Vector cannot use any of the Point operator overloads with a compile time error that there is no implicit conversion from Point to Vector. I tried adding an implicit operator to Vector: public static implicit...
0
9595
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
10059
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
10008
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
9873
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
6682
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
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3974
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
3578
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2822
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.