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

casts and pointers


[repost]
[snipped from elsewhere]
>>I can't see how to cast an integer to a pointer.
You can't. Fortran doesn't do that - not even with the C interop stuff.
Of course,you can always play around with TRANSFER, but recall that the
standard says that the resulting values are undefined when you type
cheat with TRANSFER. And you can do it in C.
You can't do it portably in C, either. I believe you can memcpy() in
to an (unsigned char *) and back again. If sizeof(int) >= sizeof(void*)
you might be able to do the cast, but the use of the value of the
int is non-portable. Those writing large model x86 code, and
who try to do such casts, know all about this one.
> cptr = C_PTR(p+1)
I suppose you are trying to use a structure constructor here. You can't
do that with C_PTR as it has (intentionally) private components. The
whole point of private components is to keep you from fiddling with the
innards. You can't write a structure constructor for a private component
- you don't even know what the components are. Now maybe you know what a
C pointer better look like inside, but accordingh to the Fortran
compiler, you don't know.
From K&R2 (close, but not exactly, the C89 standard) A6.6:

"Certain other conversions involving pointers and integers are
permitted, but have implementation defined aspects. They must
be specified by an explicit type-conversion operator, or cast."

"A pointer may be converted to an integral type large enough to
hold it; the required size is implementation-dependent. The
mapping function is also implementation dependent."

"An object of integral type may be explicitly converted to a
pointer. The mapping always carries a sufficiently wide integer
converted from a pointer back to the same pointer, but is
otherwise implementation-dependent."

Can someone in the know comment on the above?
--
wade ward
"Nicht verzagen, Bruder Grinde fragen."
Oct 17 '07 #1
0 1086

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

Similar topics

11
by: Wenjie | last post by:
Hello, Is the following statements legal (0 is actualy a pointer parameter that could be '0' and relevant to the casts) ? MyClass* p = reinterpret_cast<MyClass*>(0); MyClass* p =...
4
by: Michael Wagner | last post by:
I do some Windows kernel programming, where what I need to pass to some Kernel call is "void* Context". Sometime later, I will get that Conext back. I want to pass a class pointer to this system...
31
by: Jacob | last post by:
It is a common recommendation to use "static_cast<SomeType> someInstance" instead of the traditional infamous "(SomeType) someInstance". Should I use the same practice for simple types, i.e....
20
by: Martijn | last post by:
Hi, Those familiar with Windows programming may be familiar with the windowsx.h header. In this header macros exist that use double casts, like so (hope this is readable): #define...
47
by: sunglo | last post by:
Some time a go, in a discussion here in comp.lang.c, I learnt that it's better not to use a (sometype **) where a (void **) is expected (using a cast). Part of the discussion boiled down to the...
5
by: caleb.vandyke | last post by:
I am working with some code that is doing some pointer to structure casts and I can't figure out how the cast is being done. Here is basically the code. #include <stdio.h> #include <stdlib.h> ...
9
by: liljencrantz | last post by:
Hi, I have a piece of code that uses hashtables to store pointers to various bits of data. The hashtable sees all pointers as const void *, while the application obviously uses various other...
2
by: Noah Roberts | last post by:
I have a class, that inherits from a class that inherits virtually from another class. I have a breakdown occuring and it is not wrt the virtually inherited class but one of the other MIed pure...
81
by: jacob navia | last post by:
Hi I am still writing my tutorial book about C. Here is the section about casts. I would be interested in your opinions about this. Some people have definite views about this subject ("never...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.