Comments (5)
clang cannot compile project because of this.
error: declaration of non-local variable in 'for' loop
hashmap_foreach(key, b, &map) {
^
hashmap.h:324:5: note: expanded from macro 'hashmap_foreach'
__HASHMAP_FOREACH(__HASHMAP_MAKE_UNIQUE(__map), (key), (data), (h))
^
hashmap.h:32:10: note: expanded from macro '__HASHMAP_FOREACH'
for (HASHMAP_ITER(*(h)) __HASHMAP_UNIQUE(x, it) = hashmap_iter(h, &__HASHMAP_UNIQUE(x, it)); \
^
hashmap.h:96:5: note: expanded from macro 'HASHMAP_ITER'
struct { \
^
1 error generated.
from hashmap.
Sorry about that. I used GNU toolchains when I was developing this project, and GCC gives more leeway and allows declaring an anonymous struct in a for
loop. There is a heated discussion on this topic here: https://stackoverflow.com/questions/11903232/declaring-anonymous-struct-in-for-loop-clang-fails-to-compile
The naïve fix for this issue would be to require the caller to declare the iterator externally, but this would significantly reduce the usability of the hashmap_foreach()
macro. You'd be looking at something like:
HASHMAP_ITER(map) it;
hashmap_foreach(it, key, val, &map) { ... }
I'll think about a solution. I may be able to define the iterator type in the hashmap structure, which will allow me to avoid declaring it in the for
loop, and placate more strict compilers like Clang and Visual Studio.
from hashmap.
@NEU-Liu I just merged a fix. I added Clang to my continuous integration test build, and it's passing, so should be good to go.
from hashmap.
for (struct {int foo; int bar;} i = {0}; i.foo < 10; i.foo++);
That works on clang 12 on Linux with -std=gnu17
and -std=gnu2x
, but not on FreeBSD with clang 13... Tried both -std=gnu17
and -std=gnu2x
...
from hashmap.
Hi @bogen85 I will investigate differences in the C standard in the FreeBSD toolchain variants when time allows, but in the meantime, you might consider using the iterator interface instead of the foreach
macros. Here is an example:
HASHMAP_ITER(my_map) it;
for (it = hashmap_iter(&my_map); hashmap_iter_valid(&it); hashmap_iter_next(&it)) {
/* Access entry using hashmap_iter_*() functions */
}
The iterator interface is used internally by the foreach
macros, but has less "edgy" code in it that picky toolchains might balk at.
from hashmap.
Related Issues (13)
- Is this hashmap thread-safe? HOT 1
- A way to use a pointer as key? without compiler warnings HOT 2
- modifying key interface requirements HOT 4
- table pointer is NULL HOT 8
- global hashmap can't be seen outside of where it's declared HOT 6
- Suggestion: Consider add this library to clib https://github.com/clibs/clib? HOT 4
- Traversal error while adding HOT 1
- Add save and load from file HOT 1
- incovenient function type in hashmap_set_key_alloc_funcs HOT 1
- Multiple errors with typeof HOT 1
- Random iteration? HOT 1
- How to build in nodebug mode HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hashmap.