Hi Bill, On Sun, 2 Nov 2014 21:50:18 -0600 Bill Fischofer <bill.fischo...@linaro.org> wrote: > I'm working on code to implement the new buffer APIs and have the following > internal function: > > static inline void *get_block(struct pool_entry_s *pool) > { > void volatile *oldhead; > void volatile *newhead; > > do { > oldhead = pool->blk_freelist; > if (oldhead == NULL) break; > newhead = ((odp_buf_blk_t *)oldhead)->next; > } while (odp_cs(pool->blk_freelist,oldhead,newhead) == 0); > > return (void *)oldhead; > } > > However when compiling this generates the following strange error message: > > ./include/odp_buffer_pool_internal.h: In function 'get_block': > ./include/odp_buffer_pool_internal.h:88:14: error: cast discards > '__attribute__((noreturn))' qualifier from pointer target type > [-Werror=cast-qual] > newhead = ((odp_buf_blk_t *)oldhead)->next; > ^
On gcc version 4.9.1 it gives: warning: cast discards 'volatile' qualifier from pointer target type [-Wcast-qual] newhead = ((odp_buf_blk_t *)oldhead)->next; ^ The warning is indeed correct and suitable for -Wcast-qual, since 'oldhead' is a volatile pointer while it is casted to a non volatile pointer type. In your gcc the warning output shown is incorrect. Using -Wcast-qual is a bit evil. It won't allow you to cast away properties of pointers such as const or volatile without some tricks. The easy option would be to disable -Wcast-qual. However this might work for you: #define VOLATILE_ACCESS_PTR(p) \ ((typeof(p))(uintptr_t) *(volatile typeof(p) const *)&(p)) static inline void *get_block(struct pool_entry_s *pool) { void *oldhead; void *newhead; do { oldhead = VOLATILE_ACCESS_PTR(pool->blk_freelist); if (oldhead == NULL) break; newhead = ((odp_buf_blk_t *)oldhead)->next; } while (odp_cs(pool->blk_freelist,oldhead,newhead) == 0); return oldhead; } Advantage is pool->blk_freelist is accessed once (which I beleive was your intention), and encapsulating all details of the ugly casts needed to solve -Wcast-qual warnings into a single place. Regards, Shmulik _______________________________________________ lng-odp mailing list lng-odp@lists.linaro.org http://lists.linaro.org/mailman/listinfo/lng-odp