Wireshark mailing list archives
Re: initializing a variable with a non-constant value
From: Evan Huus <eapache () gmail com>
Date: Sun, 14 Oct 2012 13:47:53 -0400
On Sun, Oct 14, 2012 at 1:36 PM, Martin Kaiser <lists () kaiser cx> wrote:
Hi, doc/README.developer says Don't initialize variables in their declaration with non-constant values. Not all compilers support this. E.g. don't use guint32 i = somearray[2]; ... In file.c, read_packet(), we do const struct wtap_pkthdr *phdr = wtap_phdr(cf->wth); union wtap_pseudo_header *pseudo_header = wtap_pseudoheader(cf->wth); const guchar *buf = wtap_buf_ptr(cf->wth); The two things are in contradiction and I'm wondering how to fix this. Apparently, there's been no complaints about compiler problems with read_packet() so I was wondering if the limitation in README.developer is still required. Any views about this? Or any idea which compilers could potentially be affected? Thanks, Martin
This is very similar in theme to my question about variadic macros a few weeks ago [1]. The conclusion there was that they're not officially part of C89 which is Wireshark's official C version. Even though it seems all of the compilers we use support that particular C99 extension, we can't move to C99 officially because MSVC doesn't support all of it, so it's simpler for everyone if we try to stick to pure C89. It's obviously not a big deal if the occasional C99 slips in accidentally as long as it doesn't cause any build problems, but we should try to avoid it where possible. Cheers, Evan [1] https://www.wireshark.org/lists/wireshark-dev/201209/msg00142.html ___________________________________________________________________________ Sent via: Wireshark-dev mailing list <wireshark-dev () wireshark org> Archives: http://www.wireshark.org/lists/wireshark-dev Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev mailto:wireshark-dev-request () wireshark org?subject=unsubscribe
Current thread:
- initializing a variable with a non-constant value Martin Kaiser (Oct 14)
- Re: initializing a variable with a non-constant value Evan Huus (Oct 14)
- Re: initializing a variable with a non-constant value Guy Harris (Oct 14)
- Re: initializing a variable with a non-constant value Guy Harris (Oct 14)
- Re: initializing a variable with a non-constant value Evan Huus (Oct 14)