Skip to content

Commit f3caa8e

Browse files
committed
Merge pull request #253 from tbeu/Avoid-C99-style-declarations
Do not interleave code and declarations in C files
2 parents 7bee573 + 8921f9d commit f3caa8e

File tree

9 files changed

+504
-468
lines changed

9 files changed

+504
-468
lines changed

example/c/lib_buffer_unpack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ void unpack(receiver* r) {
5252
msgpack_unpack_return ret;
5353
char* buf;
5454
size_t recv_len;
55+
int recv_count = 0;
5556

5657
msgpack_unpacked_init(&result);
5758
if (msgpack_unpacker_buffer_capacity(unp) < EACH_RECV_SIZE) {
@@ -64,7 +65,6 @@ void unpack(receiver* r) {
6465
msgpack_unpacker_buffer_consumed(unp, recv_len);
6566

6667

67-
int recv_count = 0;
6868
while (recv_len > 0) {
6969
int i = 0;
7070
printf("receive count: %d %zd bytes received.:\n", recv_count++, recv_len);

example/c/simple.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33

44
int main(void)
55
{
6-
/* msgpack::sbuffer is a simple buffer implementation. */
76
msgpack_sbuffer sbuf;
7+
msgpack_packer pk;
8+
msgpack_zone mempool;
9+
msgpack_object deserialized;
10+
11+
/* msgpack::sbuffer is a simple buffer implementation. */
812
msgpack_sbuffer_init(&sbuf);
913

1014
/* serialize values into the buffer using msgpack_sbuffer_write callback function. */
11-
msgpack_packer pk;
1215
msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write);
1316

1417
msgpack_pack_array(&pk, 3);
@@ -19,10 +22,8 @@ int main(void)
1922

2023
/* deserialize the buffer into msgpack_object instance. */
2124
/* deserialized object is valid during the msgpack_zone instance alive. */
22-
msgpack_zone mempool;
2325
msgpack_zone_init(&mempool, 2048);
2426

25-
msgpack_object deserialized;
2627
msgpack_unpack(sbuf.data, sbuf.size, NULL, &mempool, &deserialized);
2728

2829
/* print the deserialized object. */

example/c/speed_test_uint32_array.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
#include <msgpack.h>
2-
#include <assert.h>
32

43
void test()
54
{
65
size_t size = 10000000;
76
msgpack_sbuffer buf;
7+
msgpack_packer * pk;
8+
size_t upk_pos = 0;
9+
msgpack_unpacked msg;
10+
811
msgpack_sbuffer_init(&buf);
912

10-
msgpack_packer * pk = msgpack_packer_new(&buf, msgpack_sbuffer_write);
13+
pk = msgpack_packer_new(&buf, msgpack_sbuffer_write);
1114

1215
msgpack_pack_array(pk, size);
1316
{
@@ -17,9 +20,6 @@ void test()
1720
}
1821
msgpack_packer_free(pk);
1922

20-
21-
size_t upk_pos = 0;
22-
msgpack_unpacked msg;
2323
msgpack_unpacked_init(&msg);
2424

2525
while (msgpack_unpack_next(&msg, buf.data, buf.size, &upk_pos)) {

example/c/speed_test_uint64_array.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
#include <msgpack.h>
2-
#include <assert.h>
32

43
void test()
54
{
65
uint64_t test_u64 = 0xFFF0000000000001LL;
76
size_t size = 10000000;
87
msgpack_sbuffer buf;
8+
msgpack_packer * pk;
9+
size_t upk_pos = 0;
10+
msgpack_unpacked msg;
11+
912
msgpack_sbuffer_init(&buf);
1013

11-
msgpack_packer * pk = msgpack_packer_new(&buf, msgpack_sbuffer_write);
14+
pk = msgpack_packer_new(&buf, msgpack_sbuffer_write);
1215

1316
msgpack_pack_array(pk, size);
1417
{
@@ -18,9 +21,6 @@ void test()
1821
}
1922
msgpack_packer_free(pk);
2023

21-
22-
size_t upk_pos = 0;
23-
msgpack_unpacked msg;
2424
msgpack_unpacked_init(&msg);
2525

2626
while (msgpack_unpack_next(&msg, buf.data, buf.size, &upk_pos)) {

0 commit comments

Comments
 (0)