how to delete void* pointer

This is a discussion on how to delete void* pointer within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by MacGyver Code: : In function `main': :9: warning: passing arg 1 of `foo' makes pointer from integer ...

  1. #31
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Quote Originally Posted by MacGyver View Post
    Code:
    : In function `main':
    :9: warning: passing arg 1 of `foo' makes pointer from integer without a cast
    Try again.
    Actually, that's just GCC being stupidly compatible with stupid programs. MSVC ought to fail to compile this.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  2. #32
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,897
    It (MSVC) doesn't. It spits out two warnings, but it compiles nevertheless.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #33
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    More stupid compilers.

    I know that it's not valid C without a cast.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #34
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by CornedBee View Post
    More stupid compilers.

    I know that it's not valid C without a cast.
    And with warnings enabled [or if you use gcc, -Werror] it will complain.

    The fact that beginners don't enable warnings, or ignore warnings is for them to learn from - and usually it's VERY obvious when you got it wrong anyways.

    Yes, C++ offers more strict type checking, but all decent compilers allow you to get warnings in C when you do that thing [even Turbo C supports a large number of warnings in this area].

    If you ignore the warnings, then that's not the fault of language, is it? The language[1] has enough information in place to check types if the code is correctly written, and the compiler is able to tell if it's not got a prototype for a function. If so, it will give a warning.

    [1] Assuming we are talking ANSI C, rather than original K&R C.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #35
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,691
    Just want to throw an FYI out there....

    If you want to test a snippet of code using a *very* standards compliant compiler, then check out Comeau's online compiler here: http://www.comeaucomputing.com/tryitout/

    gg

  6. #36
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Codeplug View Post
    Just want to throw an FYI out there....

    If you want to test a snippet of code using a *very* standards compliant compiler, then check out Comeau's online compiler here: http://www.comeaucomputing.com/tryitout/

    gg
    Wow, what an ugly website!
    If they're trying to sell their compiler, they should hire a good web designer to make the site look a little more professional. Otherwise, you see a crappy website and you automatically assume they have a crappy product too.

  7. #37
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,897
    Hehe, nice analogy.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #38
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >If they're trying to sell their compiler, they should hire a good
    >web designer to make the site look a little more professional.
    When your product is as high quality as Comeau, you don't need to "make the sale" with pretty pictures and layouts. Rather, they should make it more convenient to buy the damn thing. :P
    My best code is written with the delete key.

  9. #39
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,263
    Quote Originally Posted by CornedBee View Post
    More stupid compilers.

    I know that it's not valid C without a cast.
    There's a lot of "invalid" C out there. If compilers refused to compile it, people would move to other compilers rather than fix their code. Just how it is...

  10. #40
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by brewbuck View Post
    There's a lot of "invalid" C out there. If compilers refused to compile it, people would move to other compilers rather than fix their code. Just how it is...
    This is particularly true if the source code has "lived" for a long time, and portions [quite possibly CRITICAL or major functionality portions] haven't been changed for many, many years - if the code still works, then there's probably no reason for anyone to go through and update it, just because some compiler throws a few warnings.

    As hobbyists, we often think of "old code" as easily replacable, but if the code is working, has been tested by you, your QA-team, your customers, and is known to be bug-free and work as the customers want it to work, then there is no good reason for a manager to approve a project of 6 months to rewrite the code to compile without warnings in the latest compiler, with no other benefit - and a risk that the changes actually break something. Have you never rewritten a function just a little bit, and found that for most parts, it works exactly like before, but you missed some subtle part that makes the new function fail or behave differently in some very special case? "If it ain't broke, don't attempt to fix it!"

    The company I work for have sold the software to go into many millions of devices. If you change anything, you risk producing a bug - and if that's a "rare" bug, you may end up with a recall of our customers product from their customers, with a HUGE expense of all their customers updating the software. So we only really change things that one of our customers ask us to change!

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #41
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Quote Originally Posted by Elysia View Post
    Technically yes, since most newbies in C tend to ignore those warnings and run the code anyway.
    There's no "technically" in here. Newbies don't define a language. The standard defines the language. Warnings are there for a reason, because many C compilers allow you to do all kinds of things against the language standard in order to allow people to cut corners and write programs to utilize non-portable features. Is it smart? I don't think so. I don't like it. I don't think it's a good thing to do. Nevertheless, I know I've seen code in industry that looks like garbage in the sense that it mixes C and C++. Does it "work for them"? Yes. Is it legal? No.

    Quote Originally Posted by Elysia View Post
    Sure it's legal, but that doesn't mean it's good.
    main doesn't have a prototype and doesn't use one, so you could basically define as whatever you want.
    Oh really? Let's try void main() in C++ with MinGW:

    Code:
    : error: `main' must return `int'
    : error: return type for `main' changed to `int'
    Guess I can't define main() to anything.

    Quote Originally Posted by Elysia View Post
    I wouldn't know if it would allow or not, but since it allows silly things like passing a non-pointer to where a pointer is expected, do you really think I think of C as safe?
    It does NOT allow passing wrong arguments. The C standard is the C standard. If you violate the C standard and say it's valid C because your compiler allows you to do it, you're an idiot. You're even worse than just being just plain dumb if you ignore the warnings that tell you something is wrong. Just because your compiler allows something ridiculously stupid does not mean it's valid C.

    What you appear to be displaying is a "works-for-me" type of mentality which is just begging to run into undefined behavior, regardless of whether you use C or C++.

    Quote Originally Posted by Elysia View Post
    Passing a non-pointer where a pointer is expected - crash right away and it's so easy to do it, rather than in C++, where you'd get a compile error.
    So C++ is a superior language simply because Stroustrup turned up the warning level in the compiler like any good C programmer would? It's something I would do should I ever write a C compiler, tbh. Compliance mode first and foremost by default.

    Quote Originally Posted by Elysia View Post
    And even though void is undefined, the compiler could just assume you're dereferencing int*, just as it assumes every function returns int if it has no prototype.
    Only in your imagination. C doesn't do this.

    Quote Originally Posted by Elysia View Post
    I didn't try - no, I admit that, and I also admit that I didn't know, but I wouldn't be surprised if it WAS allowed. Whether it is or not, is an entirely different question.
    And your lack of surprise at such an event is demonstrative of your blind dislike of C out of your hard-held belief that C++ is the language. You are welcome to any opinion, naturally, and frankly, I'm not so sure I would even want to sway you to the C side. What I would like is for you to stop the needless and ridiculous C bashing, especially for baseless and rather absurd allegations of the sort that you have either directly and indirectly charged in this topic. Kindly refrain from discussing imagined features of C and C++ as a way to further your cause.

  12. #42
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,897
    Quote Originally Posted by MacGyver View Post
    Kindly refrain from discussing imagined features of C and C++ as a way to further your cause.
    There's no need... I don't enjoy this sort of arguing.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #43
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elysia View Post
    There's no need... I don't enjoy this sort of arguing.
    Don't take this the wrong way [usual way of starting a sentence that will sound somewhat offensive ], but you do seem to occassionally get into this sort of arguing - whether it's on purpose or not, and whether you enjoy it or not. I chalked that down to "not old and wise enough" Now, I can't use that exceuse, _I_ probably SHOULD know better!

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  14. #44
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,897
    Quote Originally Posted by matsp View Post
    Don't take this the wrong way [usual way of starting a sentence that will sound somewhat offensive ], but you do seem to occassionally get into this sort of arguing - whether it's on purpose or not, and whether you enjoy it or not. I chalked that down to "not old and wise enough" Now, I can't use that exceuse, _I_ probably SHOULD know better!

    --
    Mats
    Sure, it's natural that we get into arguments sometimes.
    When it's something I enjoy debating over, of course, I continue.
    When I don't enjoy it, I back out.
    And when it seems that the arguing is doing more damage than good, I back out.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #45
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Quote Originally Posted by brewbuck View Post
    There's a lot of "invalid" C out there. If compilers refused to compile it, people would move to other compilers rather than fix their code. Just how it is...
    True. The stupid part is where gcc will compile it even under -ansi -pedantic. Ha! I've seen far less serious stuff fail under -pedantic.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick Pointer Question
    By gwarf420 in forum C Programming
    Replies: 15
    Last Post: 06-01-2008, 04:47 PM
  2. Inventory tracking of dynamically allocated items
    By Mario F. in forum C++ Programming
    Replies: 11
    Last Post: 07-23-2006, 06:39 PM
  3. delete pointer inside ?
    By black in forum C++ Programming
    Replies: 7
    Last Post: 05-28-2004, 01:19 PM
  4. why is this prog crashing on delete?
    By Waldo2k2 in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 11:17 PM
  5. API "Clean Up" Functions & delete Pointers :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-10-2002, 07:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21