Skip to content

Commit 4073b90

Browse files
committed
use __typeof__ to simplify with and foreach
1 parent 6767a00 commit 4073b90

File tree

3 files changed

+13
-36
lines changed

3 files changed

+13
-36
lines changed

example/example.uvoptx

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -153,40 +153,7 @@
153153
<Name>(105=150,186,829,544,0)(106=-1,-1,-1,-1,0)(107=180,218,520,403,0)</Name>
154154
</SetRegEntry>
155155
</TargetDriverDllRegistry>
156-
<Breakpoint>
157-
<Bp>
158-
<Number>0</Number>
159-
<Type>0</Type>
160-
<LineNumber>151</LineNumber>
161-
<EnabledFlag>1</EnabledFlag>
162-
<Address>16362</Address>
163-
<ByteObject>0</ByteObject>
164-
<HtxType>0</HtxType>
165-
<ManyObjects>0</ManyObjects>
166-
<SizeOfObject>0</SizeOfObject>
167-
<BreakByAccess>0</BreakByAccess>
168-
<BreakIfRCount>1</BreakIfRCount>
169-
<Filename>&lt;1&gt;.\main.c</Filename>
170-
<ExecCommand></ExecCommand>
171-
<Expression>\\example\main.c\151</Expression>
172-
</Bp>
173-
<Bp>
174-
<Number>1</Number>
175-
<Type>0</Type>
176-
<LineNumber>158</LineNumber>
177-
<EnabledFlag>1</EnabledFlag>
178-
<Address>0</Address>
179-
<ByteObject>0</ByteObject>
180-
<HtxType>0</HtxType>
181-
<ManyObjects>0</ManyObjects>
182-
<SizeOfObject>0</SizeOfObject>
183-
<BreakByAccess>0</BreakByAccess>
184-
<BreakIfRCount>0</BreakIfRCount>
185-
<Filename>&lt;1&gt;.\main.c</Filename>
186-
<ExecCommand></ExecCommand>
187-
<Expression></Expression>
188-
</Bp>
189-
</Breakpoint>
156+
<Breakpoint/>
190157
<WatchWindow1>
191158
<Ww>
192159
<count>0</count>

example/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ int main (void)
142142

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

167-
with(example_lv1_t, &pitem->tLV1) {
167+
with(&pitem->tLV1) {
168168
_->wLV1A = 4;
169169
_->hwLV1B = 5;
170170
_->chLV1C = 6;

perf_counter.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ extern "C" {
257257
#undef __with3
258258
#undef with
259259

260+
#define __with1(__addr) \
261+
using(__typeof__(*__addr) *_=(__addr))
262+
260263
#define __with2(__type, __addr) \
261264
using(__type *_=(__addr))
262265
#define __with3(__type, __addr, __item) \
@@ -278,6 +281,13 @@ extern "C" {
278281
#undef foreach3
279282
#undef foreach
280283

284+
#define foreach1(__array) \
285+
using(__typeof__(__array[0]) *_ = __array) \
286+
for ( uint_fast32_t SAFE_NAME(count) = dimof(__array); \
287+
SAFE_NAME(count) > 0; \
288+
_++, SAFE_NAME(count)-- \
289+
)
290+
281291
#define foreach2(__type, __array) \
282292
using(__type *_ = __array) \
283293
for ( uint_fast32_t SAFE_NAME(count) = dimof(__array); \

0 commit comments

Comments
 (0)