summaryrefslogtreecommitdiffstats
path: root/rand.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-01-06 20:03:25 -0800
committerKaz Kylheku <kaz@kylheku.com>2022-01-06 20:03:25 -0800
commit2b44dc2074a358bc48c3b73b2f65f98cce355b1d (patch)
tree7d8ded9098d1e715af35b5cc8b6e7ea97097f543 /rand.c
parent52b7b42d2bcedc6936ffcb02ce2d74724f4bfaa2 (diff)
downloadtxr-2b44dc2074a358bc48c3b73b2f65f98cce355b1d.tar.gz
txr-2b44dc2074a358bc48c3b73b2f65f98cce355b1d.tar.bz2
txr-2b44dc2074a358bc48c3b73b2f65f98cce355b1d.zip
Casts have crept into the code not wrapped by macros.
It is against TXR coding conventions to use the C cast notation. The usage creeps into the code. To find instances of this, we must compile using GNU g++, and add -Wold-style-cast via EXTRA_FLAGS. * eval.c (prof_call): Use macro instead of cast. * ffi.c (pad_retval, ffi_varray_alloc, make_ffi_type_union, carray_dup, carray_replace, uint_carray, int_carray, put_carray, fill_carray): Likewise. * itypes.c (c_i64, c_u64): Likewise. * lib.c (cyr, chk_xalloc, spilt_str_keep, vector, cobj_register): Likewise. * linenoise.c (record_undo): Likewise. Also, drop one superfluous cast: wstrdup_fn returns wchar_t *. (flash, edit_insert, edit_insert_str): Use macro instead of cast. * mpi/mpi.c (s_mp_ispow2d): Likewise. * parser.c (lino_getch): Likewise. * rand.c (make_random_state, random_buf): Likewise. * stream.c (generic_get_line, do_parse_mode): Likewise. * struct.c (get_duplicate_supers, call_initfun_chain, call_postinitfun_chain): Likewise. * sysif.c (c_time): Likewise. * tree.c (tr_insert): Likewise.
Diffstat (limited to 'rand.c')
-rw-r--r--rand.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/rand.c b/rand.c
index 6202a74c..0461453f 100644
--- a/rand.c
+++ b/rand.c
@@ -200,10 +200,10 @@ val make_random_state(val seed, val warmup)
for (i = 0; i < 16; i++) {
if (len >= 4) {
- r->state[i] = (((rand32_t) data[0]) << 24 |
- ((rand32_t) data[1]) << 16 |
- ((rand32_t) data[2]) << 8 |
- ((rand32_t) data[3]));
+ r->state[i] = ((convert(rand32_t, data[0])) << 24 |
+ (convert(rand32_t, data[1])) << 16 |
+ (convert(rand32_t, data[2])) << 8 |
+ (convert(rand32_t, data[3])));
data += 4;
len -= 4;
} else if (len == 0) {
@@ -215,18 +215,18 @@ val make_random_state(val seed, val warmup)
len = 0;
break;
case 1:
- r->state[i] = (((rand32_t) data[0]) << 24);
+ r->state[i] = ((convert(rand32_t, data[0])) << 24);
len = 0;
break;
case 2:
- r->state[i] = (((rand32_t) data[0]) << 24 |
- ((rand32_t) data[1]) << 16);
+ r->state[i] = ((convert(rand32_t, data[0])) << 24 |
+ (convert(rand32_t, data[1])) << 16);
len = 0;
break;
case 3:
- r->state[i] = (((rand32_t) data[0]) << 24 |
- ((rand32_t) data[1]) << 16 |
- ((rand32_t) data[2]) << 8);
+ r->state[i] = ((convert(rand32_t, data[0])) << 24 |
+ (convert(rand32_t, data[1])) << 16 |
+ (convert(rand32_t, data[2])) << 8);
len = 0;
break;
}
@@ -455,10 +455,10 @@ val random_buf(val size, val state)
for (; sz >= 4; sz -= 4, data += 4) {
rand32_t rnd = rand32(r);
#if HAVE_LITTLE_ENDIAN
- *(rand32_t *) data = rnd;
+ *coerce(rand32_t *, data) = rnd;
#else
rnd = (0xFF00FF00U & rnd) >> 8 | (0x00FF00FFU & rnd) << 8;
- *(rand32_t *) data = (rnd << 16 | rnd >> 16);
+ *coerce(rand32_t *, data) = (rnd << 16 | rnd >> 16);
#endif
}