最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

c++ - Blatant null dereference inside boost::geometry - Stack Overflow

matteradmin9PV0评论

MSVC warned me about this code inside point_concept.hpp inside the class boost::geometry::concepts::Point:

template <typename P, std::size_t Dimension, std::size_t DimensionCount>
struct dimension_checker
{
    static void apply()
    {
        P* p = 0;
        geometry::set<Dimension>(*p, geometry::get<Dimension>(*p));
        dimension_checker<P, Dimension+1, DimensionCount>::apply();
    }
};

The code initializes p to 0 (meaning null) and then dereferences it. This seems blatant enough that I assume it's intentional; but I can't figure out the motivation for it. Does anyone know what it might be?

(One theory I came up with: Maybe they are using *p as a dummy value like std::declval? You don't need to go through constructors when declaring a pointer, so you can kind of cheat by then dereferencing the pointer and getting an (albeit garbage) value.)

Post a comment

comment list (0)

  1. No comments so far