program with external print

G

Gerry Ford

I would like to write a program that prints the address of something passed.

Declare a variable in main that equals 42:

j = 42.0;
, reference this:
pointer = &j;
, and print it out externally. If it were, instead, internal, this might
be:
! function print_it

#include <stdio.h>
// c++ no longer wants .h as std::include
int main (void) {return zero;}
ptr p;
int j = 42;

p = &j;

printf ( %p, *);

END

Grateful for your thoughtful comment.
 
M

Martin Ambuhl

Gerry said:
I would like to write a program that prints the address of something passed.
Declare a variable in main that equals 42:
j = 42.0;
, reference this:
pointer = &j;
, and print it out externally.

I have not a clue what your mean by "externally" and "internal". I'm
sure this is a limitation on my part, so I hope you will be
understanding. Your references to C++ suggest that you _may_ be in the
wrong newsgroup, but it's hard to tell since your code isn't anywhere
close to a compilable program in either C (the topic of this newsgroup,
comp.lang.c) or C++ (a different language, with its own newsgroup
comp.lang.c++). In any case, consider whether this is of help to you:

#include <stdio.h>

void print_it(int *p);

int main(void)
{
int i = 42;
int *ip = &42;
print_it(ip);
return 0;
}

void print_it(int *p)
{
printf("The pointer points to %p, which contains the value %d.\n",
(void *)p, *p);
}

[If the OP's "code" is of interest for some reason, see message
<[email protected]>]
 
V

vippstar

I have not a clue what your mean by "externally" and "internal". I'm
sure this is a limitation on my part, so I hope you will be
understanding. Your references to C++ suggest that you _may_ be in the
wrong newsgroup, but it's hard to tell since your code isn't anywhere
close to a compilable program in either C (the topic of this newsgroup,
comp.lang.c) or C++ (a different language, with its own newsgroup
comp.lang.c++). In any case, consider whether this is of help to you:

#include <stdio.h>

void print_it(int *p);

int main(void)
{
int i = 42;
int *ip = &42;
Did you perhaps mean (int[]){42} or &i?
 
G

Gerry Ford

I have not a clue what your mean by "externally" and "internal". I'm sure
this is a limitation on my part, so I hope you will be understanding.
Your references to C++ suggest that you _may_ be in the wrong newsgroup,
but it's hard to tell since your code isn't anywhere close to a compilable
program in either C (the topic of this newsgroup, comp.lang.c) or C++ (a
different language, with its own newsgroup comp.lang.c++). In any case,
consider whether this is of help to you:

#include <stdio.h>

void print_it(int *p);

int main(void)
{
int i = 42;
int *ip = &42;
print_it(ip);
return 0;
}

void print_it(int *p)
{
printf("The pointer points to %p, which contains the value %d.\n",
(void *)p, *p);
}

[If the OP's "code" is of interest for some reason, see message
<[email protected]>]
Thanks, Martin. My spirit was willing, but my syntax was weak.

I intend to use a common C extension to call that function with an address
whose content I will assign. This syntax automatically derefences, so it's
harder to know that you've got the thing done properly. I think what I want
is:
// p.c
#include <stdio.h>
void print_it(int *p)
{
printf("The pointer points to %p, which contains the value %d.\n",
(void *)p, *p);
}
, with gcc -c p.c

If main is in fortran, do I need to include C's runtime library for I/O in
the command that builds the ultimate executable, or am I covered with
stdio.h?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top