Consider an implementation that doesn't use all bits 0 to represent
a NULL pointer. Let the NULL pointer is represented by 0x12345678.
On such an implementation, if the value of NULL pointer is printed
will it be all 0's or 0x12345678
int main(void)
{
char *ptr;
ptr = 0;
printf("\nptr=% p\n",ptr);
}
What would be the output, 0 or 0x12345678 ?
I think user must be kept transparent from the internal representation
of NULL pointer. Even if the implementation is
using 0x12345678 for NULL pointer, value printed should be all
bits zero. 42 5945
>Consider an implementation that doesn't use all bits 0 to represent a NULL pointer. Let the NULL pointer is represented by 0x12345678. On such an implementation, if the value of NULL pointer is printed will it be all 0's or 0x12345678
Probably. It could just as well be printed as "(ullnay)".
What would be the output, 0 or 0x12345678 ?
It is quite possible on some implementations that the output of %p
always contains a colon.
I think user must be kept transparent from the internal representation of NULL pointer.
If that's your opinion, fine. I don't think this is justified
by the standard or shared by implementors.
Even if the implementation is using 0x12345678 for NULL pointer, value printed should be all bits zero.
Gordon L. Burditt
On Tue, 14 Jun 2005 22:50:26 -0700, junky_fellow wrote: Consider an implementation that doesn't use all bits 0 to represent a NULL pointer. Let the NULL pointer is represented by 0x12345678. On such an implementation, if the value of NULL pointer is printed will it be all 0's or 0x12345678
Either or neither. The implementation could coose to output it as, for
example, <null>
int main(void) {
char *ptr; ptr = 0;
printf("\nptr=% p\n",ptr); } } What would be the output, 0 or 0x12345678 ?
The standard does not specify the form of output of %p. There is no
requirement that it takes the form of a hex number, although it can and
some implementations do that.
I think user must be kept transparent from the internal representation of NULL pointer.
That is certainly not a requirement. All that is required is that scanf()
%p can recreate the pointer from the output of printf() %p
Even if the implementation is using 0x12345678 for NULL pointer, value printed should be all bits zero.
If you want full transparency then direct correspondance to any particular
bit pattern should be avoided.
Lawrence
Le 15/06/2005 07:50, dans 11************* ********@g47g20 00...legro ups.com,
«*ju**********@ yahoo.co.in*» <ju**********@y ahoo.co.in> a écrit*: Consider an implementation that doesn't use all bits 0 to represent a NULL pointer. Let the NULL pointer is represented by 0x12345678. On such an implementation, if the value of NULL pointer is printed will it be all 0's or 0x12345678
int main(void) {
char *ptr; ptr = 0;
printf("\nptr=% p\n",ptr); }
What would be the output, 0 or 0x12345678 ? I think user must be kept transparent from the internal representation of NULL pointer. Even if the implementation is using 0x12345678 for NULL pointer, value printed should be all bits zero.
It seems dangerous if 0 is a valid address, and it probably will be
if 0x12345678 is NULL. In that cas, I would prefer 0x12345678,
or even "(null)" or anything clearly announcing a NULL pointer.
Lawrence Kirby wrote: On Tue, 14 Jun 2005 22:50:26 -0700, junky_fellow wrote:
Consider an implementation that doesn't use all bits 0 to represent a NULL pointer. Let the NULL pointer is represented by 0x12345678. On such an implementation, if the value of NULL pointer is printed will it be all 0's or 0x12345678
Either or neither. The implementation could coose to output it as, for example, <null>
int main(void) {
char *ptr; ptr = 0;
printf("\nptr=% p\n",ptr); } } What would be the output, 0 or 0x12345678 ?
The standard does not specify the form of output of %p. There is no requirement that it takes the form of a hex number, although it can and some implementations do that.
I think user must be kept transparent from the internal representation of NULL pointer.
That is certainly not a requirement. All that is required is that scanf() %p can recreate the pointer from the output of printf() %p
Even if the implementation is using 0x12345678 for NULL pointer, value printed should be all bits zero.
If you want full transparency then direct correspondance to any particular bit pattern should be avoided.
Lawrence
Is there any way by which user can determine what is the internal
representation for a NULL pointer ? I am asking this because,
sometimes during debugging the memory dump is analysed. In that
case it would be difficult to find it is a NULL pointer or not. ju**********@ya hoo.co.in wrote: Is there any way by which user can determine what is the internal representation for a NULL pointer ? I am asking this because, sometimes during debugging the memory dump is analysed. In that case it would be difficult to find it is a NULL pointer or not.
/* BEGIN new.c */
#include <stdio.h>
int main(void)
{
void *pointer = NULL;
size_t byte;
for (byte = 0; byte != sizeof pointer; ++byte) {
printf(
"byte %lu is 0x%u\n",
(long unsigned)byte,
(unsigned)((uns igned char *)&pointer)[byte]
);
}
puts(
"There may be more than one "
"representa tion for a null pointer."
);
return 0;
}
/* END new.c */
--
pete Is there any way by which user can determine what is the internal representation for a NULL pointer ? I am asking this because, sometimes during debugging the memory dump is analysed. In that case it would be difficult to find it is a NULL pointer or not.
You can cast to an unsigned integer (if pointers and integers are
32 bits, that should work). If the compiler is very clever and
converts the NULL pointer to a 0 value, then you can try this:
Write a function "unsigned fun(unsigned x) { return x; }", and
compile, then in another file, declare this function as
"unsigned fun(char *p)" and pass it a NULL pointer. Hopefully the
result will be the internet representation of a NULL. I'm not
sure, since I've never tried this on a machine on which NULL != 0.
I made many assumptions here on integer and pointer sizes, so
it may not work at all. And on a machine where pointers and integers
are passed in a different way, it won't work either. Be careful,
that's just an idea. ju**********@ya hoo.co.in wrote: Consider an implementation that doesn't use all bits 0 to represent a NULL pointer. Let the NULL pointer is represented by 0x12345678. On such an implementation, if the value of NULL pointer is printed will it be all 0's or 0x12345678
It could be printed out as 0xdeadbeef.
--
pete ju**********@ya hoo.co.in wrote: Consider an implementation that doesn't use all bits 0 to represent a NULL pointer. Let the NULL pointer is represented by 0x12345678. On such an implementation, if the value of NULL pointer is printed will it be all 0's or 0x12345678
int main(void) { char *ptr; ptr = 0; printf("\nptr=% p\n",ptr); }
What would be the output, 0 or 0x12345678 ?
It's implementation dependent. From N869:
p The argument shall be a pointer to void. The value
of the pointer is converted to a sequence of
printing characters, in an implementation-defined
manner.
--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
In article <11************ **********@g47g 2000cwa.googleg roups.com>,
<ju**********@y ahoo.co.in> wrote: Is there any way by which user can determine what is the internal representati on for a NULL pointer ? I am asking this because, sometimes during debugging the memory dump is analysed. In that case it would be difficult to find it is a NULL pointer or not.
In all real-world implementations the NULL pointer is all-bits zero.
(Someone will post a counter-example if I'm wrong.) So if you are
really debugging with a memory dump, rather than asking a theoretical
question, there is no problem.
-- Richard This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: junky_fellow |
last post by:
Can 0x0 be a valid virtual address in the address space
of an application ?
If it is valid, then the location pointed by a NULL pointer
is also valid and application should not receive "SIGSEGV"
( i am talking of unix machine ) while trying to read that
location.
Then how can i distinguish between a NULL pointer and an invalid
location ?
Is this essential that NULL pointer should not point to any of
the location in the virtual address...
|
by: Patrick De Ridder |
last post by:
How can I turn what I want to print 90 degrees using the logic below?
Please tell me the code with which to make the modification.
Many thanks,
Patrick.
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
|
by: Rob T |
last post by:
I have a small VB program that has a printing module...very simple....and
works great. However, If I try to print to a generic printer, I get the
following error: "The data area passed to a system call is too small".
I found the following article, that I assume is similar to my problem, which
is of little help:
http://support.microsoft.com/default.aspx?scid=kb;en-us;822779
Any suggestions?
|
by: Tom |
last post by:
I am converting an old application that was printing directly to a
specialized printer device (i.e. a special label printer). It was doing this
by opening a file with the file path of 'LPT1:' and then using PRINT # to
print directly to the printer device.
Obviously, this is not going to work under VB.NET - StreamWriter won't let
you open a device like LPT1: and such. I assume I am going to have to switch
to the System.Drawing.Printing...
|
by: yossi.kreinin |
last post by:
Hi!
There is a system where 0x0 is a valid address, but 0xffffffff isn't.
How can null pointers be treated by a compiler (besides the typical
"solution" of still using 0x0 for "null")?
- AFAIK C allows "null pointers" to be represented differently then
"all bits 0". Is this correct?
- AFAIK I can't `#define NULL 0x10000' since `void* p=0;' should work
just like `void* p=NULL'. Is this correct?
| |
by: Robert Seacord |
last post by:
i am trying to print the address of a function without getting a
compiler warning (i am compiling with gcc with alot of flags).
if i try this:
printf("%p", f);
i get:
warning: format %p expects type 'void *; but argument 2 has type 'void
|
by: Matt |
last post by:
Hello. I've got a very strange problem. Basically I have a programme
where I wish to view all the strings in the argv array so I can see
what arguments are being passed to the programme.
However, when I insert the following line at the start of a FOR loop
early on the in the programme to do this:
printf("\nCommand line arguement %d: %s. \n", i , argv );
I get back the first 3, then I get a segmentation fault followed by
|
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...
|
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...
|
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,...
|
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...
| |
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |