in reply to Review of patch to avoid adding magic with rvalue $#a (XS gurus wanted)
Is it ok to define sv inside the curlies?
That shouldn't be of much concern portability-wise. Variable declarations at the beginning of a block (compound statement) have pretty much always been supported, at least since ANSI/ISO C (aka C89/C90), and - AFAIK - even before that time (i.e. old K&R-like variants).
As I wasn't entirely sure about definitions (as opposed to declarations), I tried the following snippet with the oldest compilers I could find (up to 12 years old) on various Unix platforms:
int main() { int x = 42; if (x==42) { int y = 99; x += y; } return 0; }
It did compile fine on all of them. Both in ANSI mode and when explicitly requesting the respective K&R emulation modes, i.e. cc -qlanglvl=classic (AIX), cc -Ac (HP-UX), cc -Xs (SunOS), cc -cckr (IRIX), gcc -traditional (Linux), etc. (note that -traditional is no longer supported with modern versions of gcc — I used a 10-year old gcc-2.95)
What isn't supported in strict ANSI C is mixing declarations/definitions and statements within the same block, such as
if (x==42) { x++; int y = 99; ... }
|
|---|