pass by address

  • Thread starter Bill Cunningham
  • Start date
K

Ken Brody

On 5/5/2014 3:23 PM, Bill Cunningham wrote:
[...]
Oh yes and let me add too. They seem to have helped me but I will not
mention them because guess what? They're all wrong! Even though the compiler
accepts them and they seem to function!

I'm coming in late to this discussion, but compilers are allowed to accept
invalid code, and (with some exceptions) are allowed to compile such code
without a peep.

A compiler is allowed to accept:

int i;
printf("%d %d %d\n",i++,i++,i++);

and even generate the output that you expected. That doesn't mean the code
was valid.
 
K

Ken Brody

"Malcolm McLean" <[email protected]>

Why do you need to print out a pointer?

In real life I can't think of why. But my tutorials that are no good
give me those examples. There are certain things that you don't pick up out
of the tutorials I now have that you can't get except from those with
experience.

I can think of tutorials having a good reason to want to display pointers.
Consider explaining why "str1==str2" is not the same as "strcmp(str1,str2)".

=====
#define MyString "Hello, world.\n"
char foo1[] = MyString;
char bar1[] = MyString;
char *foo2 = MyString;
char *bar2 = MyString;
....
printf("foo1 is at address %p\nbar1 is at address %p\n",foo1,bar1);
printf("foo2 points to %p\nbar2 points to %p\n",foo2,bar2);
.....
=====
The thing is I'm getting a little leary of the advice I'm
getting. It's like asking someone for directions and they point to the right
with the right arm and the left with the left arm and they don't seem to
understand what I just asked.

Perhaps it's because you ask for directions with questions like "I'm trying
to drive backwards down a one-way street, but I'm not sure which key fits
the ignition -- can you tell me how to put gas in the tank?"
 
B

Bill Cunningham

[snip]
and even generate the output that you expected. That doesn't mean the
code was valid.

They say there's a difference in coders and programmers.
 

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

Forum statistics

Threads
474,073
Messages
2,570,539
Members
47,197
Latest member
NDTShavonn

Latest Threads

Top