This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
locale.c: Move declaration to first uses
authorKarl Williamson <khw@cpan.org>
Fri, 29 Dec 2023 20:33:12 +0000 (13:33 -0700)
committerKarl Williamson <khw@cpan.org>
Sun, 31 Dec 2023 18:40:46 +0000 (11:40 -0700)
C99 allows the clearer code of declaring a variable close to its use.

This also will be helpful in a future commit.

locale.c

index da19608..caf74a3 100644 (file)
--- a/locale.c
+++ b/locale.c
@@ -6026,8 +6026,6 @@ S_my_langinfo_i(pTHX_
                  * value, as documented */
                 utf8ness_t * utf8ness)
 {
-    const char * retval = NULL;
-
     PERL_ARGS_ASSERT_MY_LANGINFO_I;
     assert(cat_index < LC_ALL_INDEX_);
 
@@ -6058,7 +6056,7 @@ S_my_langinfo_i(pTHX_
     const char * orig_switched_locale = toggle_locale_i(cat_index, locale);
 
     gwLOCALE_LOCK;
-    retval = save_to_buffer(nl_langinfo(item), retbufp, retbuf_sizep);
+    const char * retval = save_to_buffer(nl_langinfo(item), retbufp, retbuf_sizep);
     gwLOCALE_UNLOCK;
 
     if (utf8ness) {
@@ -6093,6 +6091,7 @@ S_my_langinfo_i(pTHX_
     /* Almost all the items will have ASCII return values.  Set that here, and
      * override if necessary */
     utf8ness_t is_utf8 = UTF8NESS_IMMATERIAL;
+    const char * retval = NULL;
 
     switch (item) {
       default: