Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > printing values of "arrays of pointers"

Reply
Thread Tools

printing values of "arrays of pointers"

 
 
arnuld
Guest
Posts: n/a
 
      05-05-2008
> On Sat, 03 May 2008 16:21:35 +0530, santosh wrote:


> More practically Sunsite could terminate his account with them if they
> were to be alerted to his behaviour. Their rules clearly say that users
> are only to use their own email addresses which actually exist and can
> be delivered to, in the Sender field.



I think this Server Policy is good:

http://news.aioe.org/spip.php?article3



--
http://lispmachine.wordpress.com/
my email ID is @ the above address

 
Reply With Quote
 
 
 
 
arnuld
Guest
Posts: n/a
 
      05-05-2008
> On Sat, 03 May 2008 16:21:35 +0530, santosh wrote:


> More practically Sunsite could terminate his account with them if they
> were to be alerted to his behaviour. Their rules clearly say that users
> are only to use their own email addresses which actually exist and can
> be delivered to, in the Sender field.



I have mailed them and have asked them to change their policy.





--
http://lispmachine.wordpress.com/
my email ID is @ the above address

 
Reply With Quote
 
 
 
 
arnuld
Guest
Posts: n/a
 
      05-05-2008
> On Mon, 05 May 2008 04:48:11 +0000, Richard Heathfield wrote:

> Nobody wants to be spammed. On the other hand, how would you like it if
> someone used *your* real address in *their* From field?





> All you have to do is invent an address that is in the correct form but
> guaranteed not to exist. For example, lid is a well-formed
> email address that definitely doesn't exist (because there is no top-level
> domain called "invalid"). This is not an area where originality is
> terribly important. If in doubt, use lid for From and
> Reply-To, and mung your real email address in your sig block.



how about my present address ? It doe not use any real domain name and is
different enough from common words like spam, invalid, nospam etc.

BTW, I don't see Reply-To header for my own posts, not even for the posts
of BartC and santosh but I do see Reply-To header of yours. ( I have
already enabled all headers in PAN preferences)



--
http://lispmachine.wordpress.com/
my email ID is @ the above blog.
just check the "About Myself" page

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      05-05-2008
arnuld <> writes:
>> On Mon, 05 May 2008 02:25:53 -0400, CBFalconer wrote:
>> No. People can create new domains and addresses at any time. The
>> .invalid domain is guaranteed not to exist, and thus to never cause
>> problems.

>
> so "invalid" is the only one that is usable


<OT>
No, it's not the only one, but it's the most appropriate for your
purposes. Point your web browser to <http://example.com/> and follow
the link for more information.

But even if it were the only one, why would that be a problem? How
many invalid TLDs do you need? (Hint: the correct answer is an
integer between 0 and 2.)

If you want to discuss this further, please find a newsgroup or other
forum where it's topical.
</OT>

--
Keith Thompson (The_Other_Keith) <kst->
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
arnuld
Guest
Posts: n/a
 
      05-06-2008
> On Mon, 05 May 2008 02:25:53 -0400, CBFalconer wrote:

> No. People can create new domains and addresses at any time. The
> .invalid domain is guaranteed not to exist, and thus to never cause
> problems.



so "invalid" is the only one that is usable

--
http://lispmachine.wordpress.com/
my email ID is @ the above blog.
just check the "About Myself" page

 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      05-06-2008
On 2 May, 14:44, Richard Heathfield <r...@see.sig.invalid> wrote:
> arnuld said:


> > PURPOSE: * * * * see the comments.
> > WHAT I GOT: * * *infinite loop

>
> > /* This program will simply create an array of pointers to integers
> > ** and will fill it with some values while using malloc to create
> > ** pointers to fill the array and then will print the values pointed
> > ** by those pointers
> > **
> > **/

>
> > #include <stdio.h>
> > #include <stdlib.h>

>
> > enum MAXSIZE { ARRSIZE = 100 };

>
> > int main( void )
> > {
> > * int* arr_p[ARRSIZE];
> > * int** pp;
> > * int *mp, *np;
> > * int i;

>
> > * int null_int = 0;

>
> > * pp = arr_p;
> > * np = &null_int;

>
> > * for( i = 0; i < ARRSIZE - 1; ++i )
> > * * {
> > * * * mp = malloc( sizeof( int ) );

>
> You don't check to see whether this fails to allocate the requested
> memory...
>
> > * * * mp = &i;

>
> ...which doesn't really matter, since you throw it away here.
>
> > * * * arr_p[i] = mp;
> > * * }

>
> Well done. You just filled arr_p with a bunch of pointers to i. Why
> bother with the malloc call, then? You could save yourself
> (ARRSIZE-1) * sizeof(int) bytes of memory leak by removing the malloc > call completely.
>
> > * arr_p[i] = np;

>
> > * while( **pp )

>
> pp has the value &arr_p[0], so **pp attempts to find the int value at
> *arr_p[0]. Since arr_p[0] points to i, we're looking for the value of > i.
> That value is indeterminate, because the object i never had a value
> assigned to it.


not even in the for loop?


> Thus, the behaviour is undefined. This loop could execute
> forever (the most likely possibility) or not at all (probably the
> second most likely) or something completely weird could happen.
>
> > * * {
> > * * * printf("**pp = %d\n", **pp);


if you want to print a pointer (and **pp *isn't a pointer)
use %p. Instead of trying to be clever why not use a for loop?

for (i = 0; i < ARRSIZE; i++)
printf ("%p ", (void*)arr_p[i]);

printf ("\n");


> > * * }

>
> You don't even /try/ to iterate through the array, do you? You might
> want
> to take a long hard look at Visual Basic or RCX.



--
Nick Keighley

My god it's full of stars!
Dave Bowman, on seeing HAL's source code
 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      05-06-2008
On 2 May, 15:05, arnuld <NoS...@microsoft.com> wrote:
> > On Fri, 02 May 2008 13:44:50 +0000, Richard Heathfield wrote:


> >> * for( i = 0; i < ARRSIZE - 1; ++i )
> >> * * {
> >> * * * mp = malloc( sizeof( int ) );


> > You don't check to see whether this fails to allocate the requested
> > memory...

>
> done
>
> >> * * * mp = &i;

> > ...which doesn't really matter, since you throw it away here.

>
> well, then how can I generate a new variable every-time I enter into
> the loop ?


you can't. Well you can but you don't want to.

for( i = 0; i < ARRSIZE - 1; ++i )
{
int new;
arr_p[i] = &new;
}

The Standard doesn't say if new has the same address every time,
but on almost any reasonable implementation it does. Hence you
don't want to do this.

So why not malloc an object and store its address in the array?
You probably meant to do that but your code really didn't
do that.

for( i = 0; i < ARRSIZE - 1; ++i )
{
if ((mp = malloc (sizeof (int))) == NULL)
{
fprintf (stderr, "memory error\n");
abort();
}

arr_p[i] = mp;
}


<snip>

--
Nick Keighley

-pedantic
This option is not intended to be useful; it exists only to satisfy
pedants who would otherwise claim that GNU CC fails to support the
ANSI standard.
(Using and Porting GNU CC)
 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      05-06-2008
On 6 May, 14:44, Richard Heathfield <r...@see.sig.invalid> wrote:
> Nick Keighley said:
>
> > On 2 May, 14:44, Richard Heathfield <r...@see.sig.invalid> wrote:

>
> <snip>
>
> >> Since arr_p[0] points to i, we're looking for the value of >
> >> i. That value is indeterminate, because the object i never had a value
> >> assigned to it.

>
> > not even in the for loop?

>
> Oops - good spot - apologies to OP.


some languages make it UB to acces the for loop variable
outside the loop (I think- Pascal, Alogol-60 and Ada)
but I think it is guaranteed to point one past the end
of the array after exiting from a "normal" for-loop.
(I can't be arsed to define the exit value in Standarese).


--
Nick Keighley



 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      05-06-2008
Nick Keighley <> writes:
[...]
> some languages make it UB to acces the for loop variable
> outside the loop (I think- Pascal, Alogol-60 and Ada)
> but I think it is guaranteed to point one past the end
> of the array after exiting from a "normal" for-loop.
> (I can't be arsed to define the exit value in Standarese).


There's nothing magical about a C90-style for loop. A variable that
happens to be used in one or more of the for loop header's expressions
has whatever value it has after the loop terminates. This:

int i;
for (i = 0; i < 100; i ++) {
/* code that doesn't modify i */
}
printf("i = %d\n", i);

will print "i = 100".

C99 introduces the ability to define a variable in the loop header:

for (int i = 0; i < 100; i ++) { ... }

Referring to such a variable outside the loop isn't merely undefined
bhaevior, it's impossible. (Well, you could save its address in a
pointer variable; dereferencing the pointer outside the loop would
invoke undefined behavior.)

For comparison ...

<OT>
In Pascal, a for loop specifies a range. I *think* the value is
unspecified after the loop terminates, but I don't remember -- and it
probably varies among various implementations and pseudo-standards. I
don't know about Algol-60. Ada's for loop is much more restrictive
than C's:
for I in 0 .. 99 loop
...
end loop;
``I'' is treated as a constant (a non-modifiable object) within the
body of the loop, and doesn't exist outside the loop. You could take
its address and try to refer to it from outside the loop, as you can
in C, but Ada discourages that kind of thing; if you do it anyway, you
get Ada's equivalent of undefined behavior.
</OT>

--
Keith Thompson (The_Other_Keith) <kst->
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
David Thompson
Guest
Posts: n/a
 
      05-19-2008
On Mon, 05 May 2008 02:25:53 -0400, CBFalconer <>
wrote:

> arnuld wrote:


> > how about [ <> ]? It doe not use any real domain
> > name and is different enough from common words like spam, invalid,
> > nospam etc.

>
> No. People can create new domains and addresses at any time. The
> .invalid domain is guaranteed not to exist, and thus to never cause
> problems.


With profuse apologies to Kilmer, only ICANN can make a TLD.
And except for 2char ccTLDs which defer to ISO 3162 MA,
their process is quite public and slow enough you can get plenty of
warning of a possible conflict. But .invalid is indeed guaranteed.

- formerly david.thompson1 || achar(64) || worldnet.att.net
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 2 11-27-2010 12:12 PM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-21-2007 05:52 AM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-21-2007 05:50 AM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-21-2007 05:28 AM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-18-2007 10:11 AM



Advertisments