Skip to content

Commit

Permalink
use __typeof__ to simplify with and foreach
Browse files Browse the repository at this point in the history
  • Loading branch information
GorgonMeducer committed Jul 27, 2024
1 parent 6767a00 commit 4073b90
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 36 deletions.
35 changes: 1 addition & 34 deletions example/example.uvoptx
Original file line number Diff line number Diff line change
Expand Up @@ -153,40 +153,7 @@
<Name>(105=150,186,829,544,0)(106=-1,-1,-1,-1,0)(107=180,218,520,403,0)</Name>
</SetRegEntry>
</TargetDriverDllRegistry>
<Breakpoint>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>151</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>16362</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>&lt;1&gt;.\main.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\example\main.c\151</Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>158</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>0</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>0</BreakIfRCount>
<Filename>&lt;1&gt;.\main.c</Filename>
<ExecCommand></ExecCommand>
<Expression></Expression>
</Bp>
</Breakpoint>
<Breakpoint/>
<WatchWindow1>
<Ww>
<count>0</count>
Expand Down
4 changes: 2 additions & 2 deletions example/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ int main (void)

/*! demo of __cycleof__() operation */
__cycleof__() {
foreach(example_lv0_t, s_tItem, ptItem) {
foreach(s_tItem) {
printf("Processing item with ID = %d\r\n", _->chID);
}
}
Expand All @@ -164,7 +164,7 @@ int main (void)
_->hwB = 2;
_->chC = 3;

with(example_lv1_t, &pitem->tLV1) {
with(&pitem->tLV1) {
_->wLV1A = 4;
_->hwLV1B = 5;
_->chLV1C = 6;
Expand Down
10 changes: 10 additions & 0 deletions perf_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ extern "C" {
#undef __with3
#undef with

#define __with1(__addr) \
using(__typeof__(*__addr) *_=(__addr))

#define __with2(__type, __addr) \
using(__type *_=(__addr))
#define __with3(__type, __addr, __item) \
Expand All @@ -278,6 +281,13 @@ extern "C" {
#undef foreach3
#undef foreach

#define foreach1(__array) \
using(__typeof__(__array[0]) *_ = __array) \
for ( uint_fast32_t SAFE_NAME(count) = dimof(__array); \
SAFE_NAME(count) > 0; \
_++, SAFE_NAME(count)-- \
)

#define foreach2(__type, __array) \
using(__type *_ = __array) \
for ( uint_fast32_t SAFE_NAME(count) = dimof(__array); \
Expand Down

0 comments on commit 4073b90

Please sign in to comment.