最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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.)

发布评论

评论列表(0)

  1. 暂无评论