Utility of Function Objects

This is a discussion on Utility of Function Objects within the Tech Board forums, part of the Community Boards category; O_o Well, I'll just drop some things here. If a compiler supports exceptions, at all, but doesn't ship with a ...

  1. #16
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,415
    O_o

    Well, I'll just drop some things here.

    If a compiler supports exceptions, at all, but doesn't ship with a `new' that throws an exception in the face of failure, you can always change that behavior directly all by yourself. The `new' operator is just an operator; it is an operator that calls `void * operator new (size_t)' which is only special in that it is the function that `new' calls by default. That said, if an exceptions capable compiler ships without a version of `new' that throws, it also probably doesn't have `std::bad_alloc' so you'll need to provide a definition for that as well.

    If a compiler doesn't support exceptions, then the questionable source has no meaning because it will not compile.

    If a compiler supports exceptions, but the exception mechanism is turned off the source will either not compile or fail to protect you at runtime because the throw will not be honored.

    A very picky compiler may, in the face of an `void * operator new (size_t)' implementation that doesn't throw an exception, inform you that such an implementation goes against the standard. This behavior is certainly not required.

    Because `void * operator new (size_t)' may be a user defined function linked by a third-party linker from third-party source a compiler will very likely never elide such an additional check and probably not issue a warning.

    So, if you feel you need to code in practice against a version of `new' that doesn't throw you only have two realistic options.

    Soma

  2. #17
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,581
    Visual C++ 6.0 implementation of new was buggy anyways. The most notable being the fact that building against a user-defined new(std::nothrow) handler will be honored against the debug build and return null, but actually throw when linking against the release version of the runtime and turning on code optimization. I long forgot the actual implications of this mess but to my knowledge trying to fix new() for the benefit of VC++ 6.0 is a battle you can't win.

    If there is a reason to build against a compiler like VC++ 6.0, Yarin's code will not produce the results he's expecting. Although in practice that may not matter much...
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 14
    Last Post: 12-04-2009, 05:24 PM
  2. vector of function objects
    By idleman in forum C++ Programming
    Replies: 6
    Last Post: 09-11-2009, 12:59 PM
  3. Replies: 11
    Last Post: 09-22-2006, 06:21 PM
  4. Replies: 4
    Last Post: 10-16-2003, 12:26 PM
  5. Can objects contain/return values like a function?
    By Panopticon in forum C++ Programming
    Replies: 3
    Last Post: 01-22-2003, 07:44 PM

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