473,785 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Whats the use of %p

What kind of formating can be done with %p in printf

Feb 24 '06 #1
34 2091
"Spidey" <am********@gma il.com> wrote:
What kind of formating can be done with %p in printf


None. You can use it to print a pointer value; how the output is
formatted is entirely up to the implementation.

Richard
Feb 24 '06 #2

Spidey wrote:
What kind of formating can be done with %p in printf


To print out an address.
eg.

char *p = "abc";
printf("The address of *abc* is %p\n",p);
printf("The address of p is %p\n",&p);
result may be:
The address of *abc* is 0x804841c
The address of p is 0xbffff474

Feb 24 '06 #3
"Roka" <Ro*****@gmail. com> writes:
Spidey wrote:
What kind of formating can be done with %p in printf


To print out an address.
eg.

char *p = "abc";
printf("The address of *abc* is %p\n",p);
printf("The address of p is %p\n",&p);
result may be:
The address of *abc* is 0x804841c
The address of p is 0xbffff474


"%p" expects a void* argument. Giving it a char* is ok (but poor
style IMHO); giving it char** is likely to work, but is strictly
speaking non-portable.

char *p = "abc";
printf("The address of *abc* is %p\n", (void*)p);
printf("The address of p is %p\n", (void*)&p);

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 24 '06 #4
Keith Thompson wrote:
"%p" expects a void* argument. Giving it a char* is ok (but poor
style IMHO);


I don't like the wording of the standard in repeated footnotes
on the issue of same representation
meaning to imply interchangabili ty.

C99
6.2.5 Types
31)The same representation and alignment requirements are
meant to imply interchangeabil ity as arguments to
functions, return values from functions, and members of
unions.
39)The same representation and alignment requirements are
meant to imply interchangeabil ity as arguments to
functions, return values from functions, and members of
unions.

Why doesn't the normative part of the standard just say
that it does or doesn't imply interchangeabil ity?

--
pete
Feb 24 '06 #5
"pete" <pf*****@mindsp ring.com> wrote in message
news:43******** ***@mindspring. com...
I don't like the wording of the standard in repeated footnotes
on the issue of same representation
meaning to imply interchangabili ty.

C99
6.2.5 Types
31)The same representation and alignment requirements are
meant to imply interchangeabil ity as arguments to
functions, return values from functions, and members of
unions.
39)The same representation and alignment requirements are
meant to imply interchangeabil ity as arguments to
functions, return values from functions, and members of
unions.

Why doesn't the normative part of the standard just say
that it does or doesn't imply interchangeabil ity?


Because it would then have to explain, in detail, what situations the
interchangeabil ity applies to, and that's a lot of work. To quote myself
from another thread:

: I know of two places in the normative text that describe situations where
a
: signed type and the corresponding unsigned type are interchangeable as
: arguments to functions, and those two places are quite clear already:
: 6.5.2.2p6 (calls to a function defined without a prototype) and 7.15.1.1p2
: (va_arg()). If there are supposed to be more such situations, then I'm
: afraid the footnote itself needs to be clarified. In particular, if the
: only difference between two function types T1 and T2 is in the signedness
of
: parameters, was the intent that the two types are compatible, despite of
: what 6.7.5.3p15 says? If not, which ones of the following were intended
to
: apply, if any:
:
: - it's OK to use an expression with type T1 to call a function that was
: defined as T2, even though 6.5.2.2p6 says it's undefined behaviour?
:
: - it's OK to declare the function as T1 in one translation unit and define
: as T2 in another translation unit, even though 6.2.7p1 says it's undefined
: behaviour?
:
: - it's OK to define the function as T1 and then as T2 in *the same*
: translation unit, even though 6.7p4 says it's a constraint violation?
:
: What about interchangeabil ity as return values from function? I haven't
: found any normative text that implies this kind of interchangeabil ity;
which
: of the above three situations are meant to apply if T1 and T2 have
different
: return types?

Feb 24 '06 #6
Wojtek Lerch wrote:

"pete" <pf*****@mindsp ring.com> wrote in message
news:43******** ***@mindspring. com...
I don't like the wording of the standard in repeated footnotes
on the issue of same representation
meaning to imply interchangabili ty.

C99
6.2.5 Types
31)The same representation and alignment requirements are
meant to imply interchangeabil ity as arguments to
functions, return values from functions, and members of
unions.
39)The same representation and alignment requirements are
meant to imply interchangeabil ity as arguments to
functions, return values from functions, and members of
unions.

Why doesn't the normative part of the standard just say
that it does or doesn't imply interchangeabil ity?


Because it would then have to explain, in detail, what situations the
interchangeabil ity applies to, and that's a lot of work. To quote myself
from another thread:

: I know of two places in the normative text that describe situations where
a
: signed type and the corresponding unsigned type are interchangeable as
: arguments to functions, and those two places are quite clear already:
: 6.5.2.2p6 (calls to a function defined without a prototype) and 7.15.1.1p2
: (va_arg()). If there are supposed to be more such situations, then I'm
: afraid the footnote itself needs to be clarified. In particular, if the
: only difference between two function types T1 and T2 is in the signedness
of
: parameters, was the intent that the two types are compatible, despite of
: what 6.7.5.3p15 says? If not, which ones of the following were intended
to
: apply, if any:
:
: - it's OK to use an expression with type T1 to call a function that was
: defined as T2, even though 6.5.2.2p6 says it's undefined behaviour?
:
: - it's OK to declare the function as T1 in one translation unit and define
: as T2 in another translation unit, even though 6.2.7p1 says it's undefined
: behaviour?
:
: - it's OK to define the function as T1 and then as T2 in *the same*
: translation unit, even though 6.7p4 says it's a constraint violation?
:
: What about interchangeabil ity as return values from function? I haven't
: found any normative text that implies this kind of interchangeabil ity;
which
: of the above three situations are meant to apply if T1 and T2 have
different
: return types?


I like to use linked lists with generic data pointers.
Is the cast in new.c, completely redundant?

/* BEGIN new.c */

#include <stdio.h>

int main(void)
{
struct list_node {
struct list_node *next;
void *data;
} node;
char *string = "string";

node.data = string;
puts((char *)node.data);
return 0;
}

/* END new.c */

--
pete
Feb 24 '06 #7
"pete" <pf*****@mindsp ring.com> wrote in message
news:43******** **@mindspring.c om...
Is the cast in new.c, completely redundant? .... #include <stdio.h> .... struct list_node { .... void *data;
} node; .... puts((char *)node.data);


Yes, because <stdio.h> provides a prototype for puts() that causes an
implicit conversion. But if you used printf and %s instead, it would depend
on whether you want to rely on what "everybody knows" the intent was, or
only on what a strict reading of the words promises (and depending on who
reads them).
Feb 24 '06 #8
Wojtek Lerch wrote:

"pete" <pf*****@mindsp ring.com> wrote in message
news:43******** **@mindspring.c om...
Is the cast in new.c, completely redundant? ...
#include <stdio.h>

...
struct list_node {

...
void *data;
} node;

...
puts((char *)node.data);


Yes, because <stdio.h> provides a prototype for puts() that causes an
implicit conversion.
But if you used printf and %s instead,


part_fprint is the example that I should have given,
because I actually do use the fprintf function that way.

void part_fprint(FIL E *stream, list_type *node)
{
while (node != NULL) {
fprintf(stream, "%s\n", (char *)node -> data);
node = node -> next;
}
}
it would depend
on whether you want to rely on what "everybody knows"
the intent was, or only on what a strict reading of the
words promises (and depending on who reads them).


Thank you.
I'll keep the cast in part_fprint.

--
pete
Feb 24 '06 #9
Wojtek Lerch wrote:
: - it's OK to define the function as T1 and then as T2 in *the same* ^^^^^^
I meant "declare", of course. :-) : translation unit, even though 6.7p4 says it's a constraint violation?

Feb 24 '06 #10

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

Similar topics

9
3842
by: cricketunes | last post by:
Hi folks, this one's had me stumped! $conn=ora_logon("cricketunes@pickles","j8j3kf"); if ($conn != TRUE) die("Unable to connect to oracle, exiting...\n"); $cursor = ora_open($conn); if ($cursor != TRUE) die("Unable to open a cursor, exiting...\n");
5
2094
by: Mike M | last post by:
Hi all, I ahve the following SQL string but when i try to response.Write it there is a error where the ',' should be between "city" and "County" SQL = "INSERT * INTO customers (Company_Name, Category, Contact_Name, Contact_Title, Address_1, Address_2, City, County, Post_Code, Phone_1, Phone_2, Fax, Web_URL, email_Address, Delivery, Notes)" SQL = SQL & " VALUES('" & Request.Form("Company_Name") & "','" &
6
3471
by: Colin Steadman | last post by:
I have created a function to kill all session variables that aren't in a safe list. This is the function - Sub PurgeSessionVariables For Each Item In Session.Contents Select Case Trim(Item) Case "Authenticated" Case "CI_CODE" Case "organisation_description" Case "location_description"
3
5366
by: Kevin Steffer | last post by:
Hi group I have a webform which I want to make an ftp connection for a filetransfer from. The thing is when I use the WebRequest class it says "The URI prefix is not recognized" and my URI is ftp://localhost/ Then I discovered that the WebRequest class has a RegisterPrefix method which takes a string as prefix and it needs a System.Net.IWebRequestCreate but how is such one made ?
2
1577
by: SOR | last post by:
I'm writing a guestbook and given the number of entrys the guestbook might have can vary quite a lot - the nav links to view the guestbook entrys need to generated live at the time to suit . Whats a good method to get the effect .
3
2395
by: Chris Geerdink | last post by:
combo with PHP. what is wrong with the Javascript? else { include("mysql.php"); $query1 = mysql_query("INSERT INTO gbook (naam, email, text) VALUES ('".$_POST."', '".$_POST."', '".$_POST."')"); ?> <script language="JavaScript"> <!--
4
2006
by: David Lozzi | last post by:
OK simple question. Whats the default value for an string() array? sub LoadStuff(byval one as integer, byval two as string, optional byval three() as string = ??) Its driving me nuts! Thanks! --
4
2772
by: sophie | last post by:
Whats going on here: Read in a number as a string: scanf("%s", &number); number = 12345, for arguements sake Print it like this its fine:
7
2231
by: Mike Barnard | last post by:
It's a simple test... VERY SIMPLE. But... In an external stlyesheet some attributes don't show. With the same styles cut and pasted to the test internally it works as expected. Anyone tell me why? Its probably sooooooo obvious, but it is 1.19 am! Thanks. www.thunderin.co.uk/
7
2275
by: Paulo | last post by:
Hi, what is diference between: File -New Web Site and File -New Project -VB/C# -Web Application ?????? VS 2005
0
9645
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
10325
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, 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...
0
10148
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
10091
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
9950
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...
1
7499
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
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();...
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
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.