Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > gethostbyname() ---- Delete Resulting Pointer?

Reply
Thread Tools

gethostbyname() ---- Delete Resulting Pointer?

 
 
Lew Pitcher
Guest
Posts: n/a
 
      12-06-2007
On Dec 6, 2:59 pm, aj <(E-Mail Removed)> wrote:
> On Dec 6, 2:39 pm, "Joachim Schmitz" <(E-Mail Removed)>
> wrote:
>
> > "aj" <(E-Mail Removed)> schrieb im Newsbeitragnews:(E-Mail Removed)...> On Dec 6, 2:14 pm, Lew Pitcher <(E-Mail Removed)> wrote:
> > >> On Dec 6, 1:36 pm, aj <(E-Mail Removed)> wrote:

> > ...
> > > As usual, you guys are no help, just sticklers for details.

>
> > > Thanks for the non-help.

>
> > And you believe that this statement helps in getting helped? I guess this
> > just helps in getting you plonked...

>
> > You've been given all help there is, within topicalitiy of this group, which
> > in this case it pointing you to the groups where you might find help

>
> > Bye, Jojo

>
> My question wasn't about "delete" or "new". My question was if I am
> responsible for deallocating the pointer provided by a certain
> function. I wasn't aware that that particular function,
> gethostbyname(), isn't in the C standard. Regardless, it is still C
> syntax, compiled by a C compiler. I will save future (read: all)
> questions for a more appropriate newsgroup. Sorry you felt the need
> to plonk me.


When you provided example code that could not be C (even though you
say that you compile it with a C compiler) and stated that
> I am under the impression that you don't delete anything unless you
> personally "new'ed" it. Is this theory correct in this situation?

you took the question out of the realm of the C language.

How can we correctly answer the (implied) question of "Is the theory
that you don't delete anything unless you personally 'new'ed it?" when
the C language does not recognize the concept of "new"ing anything,
nor of "delete"ing anything? You are asking a question (apparently)
about the C++ language, and the responsibility of a C++ programmer to
write correct C++ programs. That question we cannot answer.

Had you asked
"Is the theory that you don't free() anyting unless you've personally
malloc()ed (or calloc()ed or realloc()ed) it?"
then we could have answered, for your question would be answerable
within the confines of the C language and best-practices of C
programming.

Just so you know...
 
Reply With Quote
 
 
 
 
John Gordon
Guest
Posts: n/a
 
      12-06-2007
In <(E-Mail Removed)> aj <(E-Mail Removed)> writes:

> As usual, you guys are no help, just sticklers for details.


One would infer that when you have the flu, you go to your local grocery
store and ask a stockboy what to do about it, and are offended when he
suggests you ask a doctor.

--
John Gordon A is for Amy, who fell down the stairs
http://www.velocityreviews.com/forums/(E-Mail Removed) B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

 
Reply With Quote
 
 
 
 
aj
Guest
Posts: n/a
 
      12-06-2007
On Dec 6, 3:22 pm, Lew Pitcher <(E-Mail Removed)> wrote:
> On Dec 6, 2:59 pm, aj <(E-Mail Removed)> wrote:
>
>
>
>
>
> > On Dec 6, 2:39 pm, "Joachim Schmitz" <(E-Mail Removed)>
> > wrote:

>
> > > "aj" <(E-Mail Removed)> schrieb im Newsbeitragnews:(E-Mail Removed)-ps.com...> On Dec 6, 2:14 pm, Lew Pitcher <(E-Mail Removed)> wrote:
> > > >> On Dec 6, 1:36 pm, aj <(E-Mail Removed)> wrote:
> > > ...
> > > > As usual, you guys are no help, just sticklers for details.

>
> > > > Thanks for the non-help.

>
> > > And you believe that this statement helps in getting helped? I guess this
> > > just helps in getting you plonked...

>
> > > You've been given all help there is, within topicalitiy of this group, which
> > > in this case it pointing you to the groups where you might find help

>
> > > Bye, Jojo

>
> > My question wasn't about "delete" or "new". My question was if I am
> > responsible for deallocating the pointer provided by a certain
> > function. I wasn't aware that that particular function,
> > gethostbyname(), isn't in the C standard. Regardless, it is still C
> > syntax, compiled by a C compiler. I will save future (read: all)
> > questions for a more appropriate newsgroup. Sorry you felt the need
> > to plonk me.

>
> When you provided example code that could not be C (even though you
> say that you compile it with a C compiler) and stated that> I am under the impression that you don't delete anything unless you
> > personally "new'ed" it. Is this theory correct in this situation?

>
> you took the question out of the realm of the C language.
>
> How can we correctly answer the (implied) question of "Is the theory
> that you don't delete anything unless you personally 'new'ed it?" when
> the C language does not recognize the concept of "new"ing anything,
> nor of "delete"ing anything? You are asking a question (apparently)
> about the C++ language, and the responsibility of a C++ programmer to
> write correct C++ programs. That question we cannot answer.
>
> Had you asked
> "Is the theory that you don't free() anyting unless you've personally
> malloc()ed (or calloc()ed or realloc()ed) it?"
> then we could have answered, for your question would be answerable
> within the confines of the C language and best-practices of C
> programming.
>
> Just so you know...- Hide quoted text -
>
> - Show quoted text -


Lew,

I understand your point. You are right, the sample program I
provided is not pure C. I should have removed the "delete" call prior
to posting, and should have rephrased the question to be more C'ish.
That being said, I have come to conclusion that I am not responsible
for the resulting memory, and have removed the delete call.

Thanks,
AJ
 
Reply With Quote
 
aj
Guest
Posts: n/a
 
      12-06-2007
On Dec 6, 3:25 pm, John Gordon <(E-Mail Removed)> wrote:
> In <(E-Mail Removed)> aj <(E-Mail Removed)> writes:
>
> > As usual, you guys are no help, just sticklers for details.

>
> One would infer that when you have the flu, you go to your local grocery
> store and ask a stockboy what to do about it, and are offended when he
> suggests you ask a doctor.
>
> --
> John Gordon A is for Amy, who fell down the stairs
> (E-Mail Removed) B is for Basil, assaulted by bears
> -- Edward Gorey, "The Gashlycrumb Tinies"


Acknowledged. Except you guys aren't stockboys. Stockboys don't know
what to do about the flu. You hardened C types, however, have the
knowledge to provide insight into my dilemna, so I dismiss your
analogy !

 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      12-06-2007
aj wrote, On 06/12/07 19:59:
> On Dec 6, 2:39 pm, "Joachim Schmitz" <(E-Mail Removed)>
> wrote:
>> "aj" <(E-Mail Removed)> schrieb im Newsbeitragnews:(E-Mail Removed)...> On Dec 6, 2:14 pm, Lew Pitcher <(E-Mail Removed)> wrote:
>>>> On Dec 6, 1:36 pm, aj <(E-Mail Removed)> wrote:

>> ...
>>> As usual, you guys are no help, just sticklers for details.
>>> Thanks for the non-help.

>> And you believe that this statement helps in getting helped? I guess this
>> just helps in getting you plonked...
>>
>> You've been given all help there is, within topicalitiy of this group, which
>> in this case it pointing you to the groups where you might find help
>>
>> Bye, Jojo

>
> My question wasn't about "delete" or "new".


Your code used delete and your question mentioned them, and they are
enough to show that your code is NOT C code.

> My question was if I am
> responsible for deallocating the pointer provided by a certain
> function. I wasn't aware that that particular function,
> gethostbyname(), isn't in the C standard.


That is almost forgiveable, but basic research (i.e. reading the man
page since you mentioned this was a problem on Linux) would have shown
you that it is not standard C.

> Regardless, it is still C
> syntax, compiled by a C compiler.


Any C compiler when operating as a C compiler would have rejected your
code because it was not C code. As you were told new and delete are not
part of C.

> I will save future (read: all)
> questions for a more appropriate newsgroup. Sorry you felt the need
> to plonk me.


Well, you've saved me from having to plonk you. Had I seen this post
earlier I would not have bothered with the post telling you the correct
group to ask in.
--
Flash Gordon
 
Reply With Quote
 
Lew Pitcher
Guest
Posts: n/a
 
      12-06-2007
On Dec 6, 3:25 pm, aj <(E-Mail Removed)> wrote:
> On Dec 6, 3:22 pm, Lew Pitcher <(E-Mail Removed)> wrote:
>
>
>
> > On Dec 6, 2:59 pm, aj <(E-Mail Removed)> wrote:

>
> > > On Dec 6, 2:39 pm, "Joachim Schmitz" <(E-Mail Removed)>
> > > wrote:

>
> > > > "aj" <(E-Mail Removed)> schrieb im Newsbeitragnews:(E-Mail Removed)-ps.com...> On Dec 6, 2:14 pm, Lew Pitcher <(E-Mail Removed)> wrote:
> > > > >> On Dec 6, 1:36 pm, aj <(E-Mail Removed)> wrote:
> > > > ...
> > > > > As usual, you guys are no help, just sticklers for details.

>
> > > > > Thanks for the non-help.

>
> > > > And you believe that this statement helps in getting helped? I guess this
> > > > just helps in getting you plonked...

>
> > > > You've been given all help there is, within topicalitiy of this group, which
> > > > in this case it pointing you to the groups where you might find help

>
> > > > Bye, Jojo

>
> > > My question wasn't about "delete" or "new". My question was if I am
> > > responsible for deallocating the pointer provided by a certain
> > > function. I wasn't aware that that particular function,
> > > gethostbyname(), isn't in the C standard. Regardless, it is still C
> > > syntax, compiled by a C compiler. I will save future (read: all)
> > > questions for a more appropriate newsgroup. Sorry you felt the need
> > > to plonk me.

>
> > When you provided example code that could not be C (even though you
> > say that you compile it with a C compiler) and stated that> I am under the impression that you don't delete anything unless you
> > > personally "new'ed" it. Is this theory correct in this situation?

>
> > you took the question out of the realm of the C language.

>
> > How can we correctly answer the (implied) question of "Is the theory
> > that you don't delete anything unless you personally 'new'ed it?" when
> > the C language does not recognize the concept of "new"ing anything,
> > nor of "delete"ing anything? You are asking a question (apparently)
> > about the C++ language, and the responsibility of a C++ programmer to
> > write correct C++ programs. That question we cannot answer.

>
> > Had you asked
> > "Is the theory that you don't free() anyting unless you've personally
> > malloc()ed (or calloc()ed or realloc()ed) it?"
> > then we could have answered, for your question would be answerable
> > within the confines of the C language and best-practices of C
> > programming.

>
> > Just so you know...- Hide quoted text -

>
> > - Show quoted text -

>
> Lew,
>
> I understand your point. You are right, the sample program I
> provided is not pure C. I should have removed the "delete" call prior
> to posting, and should have rephrased the question to be more C'ish.
> That being said, I have come to conclusion that I am not responsible
> for the resulting memory, and have removed the delete call.


As a rule of thumb, you are responsible for deallocating any object
that you dynamically allocate through the malloc() tools. However, in
C (especially in many C standard and 3rd-party library functions, the
opposite is not true: if the dynamic object was allocated elsewhere,
it /may/ be your responsibility to free() it at the appropriate place.

Some functions return "dynamic" objects that are allocated as static
variables within the function. From the outside (the caller's POV)
there is no way to distinguish these objects from dynamic objects that
are allocated using malloc() within the called function. For
malloc()ed objects, the caller is often responsible for free()ing the
memory, but for static objects, the caller *must not* free() the
memory. You have to read the documentation on the function that you
are calling, and find out which is expected of you.

Think of this example...

char * dyn_A(void)
{
static char array[] = "Do not free()";
return array;
}

char * dyn_B(void)
{
return malloc(4);
}

void MyFunc(void)
{
char *objA, *objB;

objA = dyn_A();
objB = dyn_B();

/* OK, do I free() objA? How about objB? How does MyFunc() know?
*/

}


 
Reply With Quote
 
Al Balmer
Guest
Posts: n/a
 
      12-06-2007
On Thu, 6 Dec 2007 12:25:42 -0800 (PST), aj <(E-Mail Removed)> wrote:

>That being said, I have come to conclusion that I am not responsible
>for the resulting memory, and have removed the delete call.


Usually, it's not good or necessary to guess about this sort of thing.
The documentation for the function call should tell you whether it is
your responsibility to free the memory.

Another pitfall - some functions might provide a pointer to static
data, which will be overwritten on the next call. In this case, you
need to allocate memory yourself, copy the data, and free the memory
when you're done.

--
Al Balmer
Sun City, AZ
 
Reply With Quote
 
jameskuyper@verizon.net
Guest
Posts: n/a
 
      12-06-2007
aj wrote:
> On Dec 6, 3:25 pm, John Gordon <(E-Mail Removed)> wrote:
> > In <(E-Mail Removed)> aj <(E-Mail Removed)> writes:
> >
> > > As usual, you guys are no help, just sticklers for details.

> >
> > One would infer that when you have the flu, you go to your local grocery
> > store and ask a stockboy what to do about it, and are offended when he
> > suggests you ask a doctor.

....
> Acknowledged. Except you guys aren't stockboys. Stockboys don't know
> what to do about the flu. You hardened C types, however, have the
> knowledge to provide insight into my dilemna, so I dismiss your
> analogy !


Just because the stockboy works with food, would you go to him for
advice about how to grow a cucumber? He might happen to know, but
would you go out of your way to pose the question to the stockboy
rather than to a gardner or a farmer?

Just because we're C experts doesn't mean we know a lot about every
library written with a C interface. When you have a question about a
library which contains a function named gethostbyname(), you should
pose your questions in a forum devoted to that library.

Many of us have used that library; some are even familiar with that
particular function (not including me), but you'll get a lot more help
in the right forum than in this one.
 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      12-06-2007
Lew Pitcher wrote:

> Sorry, but C does not have
> - a keyword called "delete",
> - a keyword called "new"
> - a standard function called gethostbyname()
> - a standard struture called hostent


> You probably want to discuss this topic in comp.lang.c++


As C++ is missing items 3 and 4, that seems unlikely.



Brian
 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      12-06-2007
aj wrote:


> As usual, you guys are no help, just sticklers for details.


Another idiot to plonk.




Brian
 
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
problems with decoding: resulting image is corrupt Bjorn Jensen Perl 2 03-22-2005 06:52 PM
How get resulting HTML of datagrid VB Programmer ASP .Net 3 08-04-2004 10:44 PM
SHA1 length of resulting hash Dil via .NET 247 ASP .Net 0 08-04-2004 12:53 PM
ASP Control names in resulting HTML Anatoli Trifonov ASP .Net 5 06-07-2004 05:36 PM
Setting a Range Parameter in a crystal report and streaming resulting report as a pdf James Wallace ASP .Net 0 10-17-2003 04:42 PM



Advertisments