Cpp.OffsetofExpression Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the offsetof_expression nodes in the syntax tree of your code
Since R2026a
Description
The PQL class Cpp.OffsetofExpression represents the node offsetof_expression in the syntax tree of your code. It models an offsetof(type, member) expression in C/C++.
#include <cstddef>
struct MyStruct {
int field;
double anotherField;
};
void foo() {
std::size_t offset1 = offsetof(MyStruct, field);
std::size_t offset2 = offsetof(MyStruct, anotherField);
}The two offsetof(MyStruct, ...) expressions in foo
correspond to offsetof_expression nodes and are the nodes matched by
Cpp.OffsetofExpression class.
Predicates
| Type | Raisable | Printable |
|---|---|---|
OffsetofExpression
| Yes | No |
This class defines these predicates that act on the objects of this class. In addition, objects of this class can access the predicates defined by the base class AstNodeProperties. An object of this class is an object of AstNodeProperties class.
| Predicates | Description | Example |
|---|---|---|
is(required OffsetofExpression &oe)
| Checks whether a node in the query is an offsetof_expression
and binds it to oe. Use it to start working directly with an
offsetof node. | This PQL defect checks for any defect find_offsetof = when
Cpp.OffsetofExpression.is(&oe)
and oe.nodeText(&txt)
raise "Found offsetof: \"{txt}\""
on oeIn this C++ code, the defect finds each
#include <cstddef>
struct MyStruct { int field; };
int main() {
std::size_t o = offsetof(MyStruct, field);
(void)o;
return 0;
} |
cast(Cpp.Node.Node node, required OffsetofExpression &cast)
| Binds cast to the offsetof_expression if
the given node is such an expression. Use when you already have a
generic Node and need the specific
OffsetofExpression. | This PQL defect checks for an defect cast_node_to_offsetof =
when
Cpp.CompoundStatement.is(&cs)
and cs.getADescendant(&node)
and Cpp.OffsetofExpression.cast(node, &oe)
and oe.nodeText(&txt)
raise "Cast to offsetof matched: \"{txt}\""
on oeIn this C++ code, the defect finds the
#include <cstddef>
struct S { int a; };
int main() {
std::size_t off = offsetof(S, a);
(void)off;
return 0;
} |
isa(Cpp.Node.Node node)
| Returns true if the given generic node is an
offsetof_expression. Use in boolean checks or negations where
you have a Node. | This PQL defect checks for defect cast_node_to_offsetof =
when
Cpp.CompoundStatement.is(&cs)
and cs.getADescendant(&node)
and Cpp.OffsetofExpression.isa(node)
and node.nodeText(&txt)
raise " offsetof matched: \"{txt}\""
on nodeIn this C++ code, the defect finds the
#include <cstddef>
struct T { double x; };
int main() {
std::size_t o = offsetof(T, x);
(void)o;
return 0;
} |
type(OffsetofExpression self, Cpp.Node.Node &child)
| Binds child to the type node used as the first argument of
the offsetof. Use it to inspect the type whose member offset is
taken. | This PQL defect checks for the type component inside an
defect offsetof_type =
when
Cpp.OffsetofExpression.is(&oe)
and oe.type(&tp)
and tp.nodeText(&txt)
raise "offsetof type: \"{txt}\""
on oeIn this C++ code, the defect extracts
#include <cstddef>
struct MyStruct { int field; };
int main() {
std::size_t x = offsetof(MyStruct, field);
(void)x;
return 0;
} |
member(OffsetofExpression self, Cpp.Node.Node &child)
| Binds child to the member node used as the second argument
of the offsetof. Use it to inspect which member's offset is
requested. | This PQL defect checks for the member identifier inside an
defect offsetof_member =
when
Cpp.OffsetofExpression.is(&oe)
and oe.member(&mb)
and mb.nodeText(&txt)
raise "offsetof member: \"{txt}\""
on oeIn this C++ code, the defect extracts
#include <cstddef>
struct MyStruct { int field; };
int main() {
std::size_t y = offsetof(MyStruct, field);
(void)y;
return 0;
} |
getEnclosingOffsetofExpression(Cpp.Node.Node child, required
OffsetofExpression &parent)
| Finds the nearest offsetof_expression ancestor of
child and binds it to parent. Use it when
you have a subnode and need the surrounding offsetof. | This PQL defect checks for an defect find_enclosing_offsetof =
when
Cpp.TypeIdentifier.is(&id)
and id.toNode(&node)
and Cpp.OffsetofExpression.getEnclosingOffsetofExpression(node, &oe)
and oe.nodeText(&txt)
raise "Enclosing offsetof: \"{txt}\""
on oeIn this C++ code, the defect starts from the type
identifier node
#include <cstddef>
struct MyStruct { int field; };
int main() {
std::size_t z = offsetof(MyStruct, field);
(void)z;
return 0;
} |
isEnclosedInOffsetofExpression(Cpp.Node.Node child)
| Returns true when the given child node has an
offsetof_expression as an ancestor. Use it to test whether a
node appears inside an offsetof. | This PQL defect checks whether a node is inside any
defect inside_offsetof =
when
Cpp.FieldIdentifier.is(&id)
and id.toNode(&node)
and Cpp.OffsetofExpression.isEnclosedInOffsetofExpression(node)
raise "Field Identifier is inside an offsetof"
on nodeIn this C++ code, the defect detects that the
identifier
#include <cstddef>
struct MyStruct { int field; };
int main() {
std::size_t k = offsetof(MyStruct, field);
(void)k;
return 0;
} |
Version History
Introduced in R2026a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)