]> granicus.if.org Git - icu/commitdiff
ICU-20438 BRS64RC Fix Clang compiler warnings in ICU4C samples
authorJeff Genovy <29107334+jefgen@users.noreply.github.com>
Fri, 22 Feb 2019 05:48:23 +0000 (21:48 -0800)
committerJeff Genovy <29107334+jefgen@users.noreply.github.com>
Sat, 23 Feb 2019 01:10:39 +0000 (17:10 -0800)
icu4c/source/samples/datefmt/main.cpp
icu4c/source/samples/numfmt/util.cpp
icu4c/source/samples/props/props.cpp
icu4c/source/samples/udata/writer.c
icu4c/source/samples/ustring/ustring.cpp

index dd1796a989671ab4e4bdb077aa6a42be32144a23..9fb22e50530e96492bad27e92037abb66f9946b1 100644 (file)
@@ -48,13 +48,13 @@ int main(int argc, char **argv) {
     UDate date;
 
     // The languages in which we will display the date
-    static char* LANGUAGE[] = {
+    static const char* LANGUAGE[] = {
         "en", "de", "fr"
     };
     static const int32_t N_LANGUAGE = sizeof(LANGUAGE)/sizeof(LANGUAGE[0]);
 
     // The time zones in which we will display the time
-    static char* TIMEZONE[] = {
+    static const char* TIMEZONE[] = {
         "America/Los_Angeles",
         "America/New_York",
         "Europe/Paris",
index ad6f008b7ee8f9d736f836d6be7de1e258f87470..f6e405bdd7337465f4dbd944700489c6ddb216c5 100644 (file)
@@ -8,6 +8,9 @@
  * others. All Rights Reserved.
  *************************************************************************/
 
+#define __STDC_FORMAT_MACROS 1
+#include <inttypes.h>
+
 #include "unicode/unistr.h"
 #include "unicode/fmtable.h"
 #include <stdio.h>
@@ -95,10 +98,15 @@ UnicodeString formattableToString(const Formattable& f) {
             return UnicodeString(buf, "");
         }
     case Formattable::kLong:
+        {
+            char buf[256];
+            sprintf(buf, "%" PRId32 "L", f.getLong());
+            return UnicodeString(buf, "");
+        }
     case Formattable::kInt64:
         {
             char buf[256];
-            sprintf(buf, "%ldL", f.getLong());
+            sprintf(buf, "%" PRId64 "L", f.getInt64());
             return UnicodeString(buf, "");
         }
     case Formattable::kString:
index da9408dee5093977b0b10d76341420f876de1ef2..f1a148651cd9291f4d5bef06512a6afb64267c42 100644 (file)
@@ -23,6 +23,9 @@
 *   for Unicode character properties.
 */
 
+#define __STDC_FORMAT_MACROS 1
+#include <inttypes.h>
+
 #include <stdio.h>
 #include "unicode/utypes.h"
 #include "unicode/uchar.h"
@@ -38,13 +41,13 @@ printProps(UChar32 codePoint) {
     u_charName(codePoint, U_UNICODE_CHAR_NAME, buffer, sizeof(buffer), &errorCode);
 
     /* print the code point and the character name */
-    printf("U+%04lx\t%s\n", codePoint, buffer);
+    printf("U+%04" PRId32 "\t%s\n", codePoint, buffer);
 
     /* print some properties */
     printf("  general category (numeric enum value): %u\n", u_charType(codePoint));
 
     /* note: these APIs do not provide the data from SpecialCasing.txt */
-    printf("  is lowercase: %d  uppercase: U+%04lx\n", u_islower(codePoint), u_toupper(codePoint));
+    printf("  is lowercase: %d  uppercase: U+%04" PRId32 "\n", u_islower(codePoint), u_toupper(codePoint));
 
     printf("  is digit: %d  decimal digit value: %d\n", u_isdigit(codePoint), u_charDigitValue(codePoint));
 
index 47348222238d8badf7a23cc8bf9f3a05dc733b9a..ba81e462957041efdd9d87face95a7e0d3e16dff 100644 (file)
@@ -70,7 +70,7 @@ main(int argc, const char *argv[]) {
     uint16_t intValue=2000;
     
     long dataLength;
-    uint32_t size;
+    size_t size;
 #ifdef WIN32
     char *currdir = _getcwd(NULL, 0);
 #else
@@ -107,19 +107,8 @@ main(int argc, const char *argv[]) {
 
 
     if(dataLength!=(long)size) {
-        fprintf(stderr, "Error: data length %ld != calculated size %lu\n", dataLength, size);
+        fprintf(stderr, "Error: data length %ld != calculated size %zu\n", dataLength, size);
         exit(U_INTERNAL_PROGRAM_ERROR);
     }
     return 0;
 }
-
-
-
-
-
-
-
-
-
-
-
index 4f0101d5edb3722c961fd3890a7804081d9fc1bd..a123c832a549f391b93fcf81f9e0e5f1763963ab 100644 (file)
@@ -23,6 +23,9 @@
 *   with ICU.
 */
 
+#define __STDC_FORMAT_MACROS 1
+#include <inttypes.h>
+
 #include <stdio.h>
 #include "unicode/utypes.h"
 #include "unicode/uchar.h"
@@ -299,7 +302,7 @@ static void demoCaseMapInC() {
     if(U_SUCCESS(errorCode)) {
         printUString("full-lowercased/en: ", buffer, length);
     } else {
-        printf("error in u_strToLower(en)=%ld error=%s\n", length, u_errorName(errorCode));
+        printf("error in u_strToLower(en)=%" PRId32 " error=%s\n", length, u_errorName(errorCode));
     }
     /* lowercase/Turkish */
     errorCode=U_ZERO_ERROR;
@@ -307,7 +310,7 @@ static void demoCaseMapInC() {
     if(U_SUCCESS(errorCode)) {
         printUString("full-lowercased/tr: ", buffer, length);
     } else {
-        printf("error in u_strToLower(tr)=%ld error=%s\n", length, u_errorName(errorCode));
+        printf("error in u_strToLower(tr)=%" PRId32 " error=%s\n", length, u_errorName(errorCode));
     }
     /* uppercase/English */
     errorCode=U_ZERO_ERROR;
@@ -315,7 +318,7 @@ static void demoCaseMapInC() {
     if(U_SUCCESS(errorCode)) {
         printUString("full-uppercased/en: ", buffer, length);
     } else {
-        printf("error in u_strToUpper(en)=%ld error=%s\n", length, u_errorName(errorCode));
+        printf("error in u_strToUpper(en)=%" PRId32 " error=%s\n", length, u_errorName(errorCode));
     }
     /* uppercase/Turkish */
     errorCode=U_ZERO_ERROR;
@@ -323,7 +326,7 @@ static void demoCaseMapInC() {
     if(U_SUCCESS(errorCode)) {
         printUString("full-uppercased/tr: ", buffer, length);
     } else {
-        printf("error in u_strToUpper(tr)=%ld error=%s\n", length, u_errorName(errorCode));
+        printf("error in u_strToUpper(tr)=%" PRId32 " error=%s\n", length, u_errorName(errorCode));
     }
     /* titlecase/English */
     errorCode=U_ZERO_ERROR;
@@ -331,7 +334,7 @@ static void demoCaseMapInC() {
     if(U_SUCCESS(errorCode)) {
         printUString("full-titlecased/en: ", buffer, length);
     } else {
-        printf("error in u_strToTitle(en)=%ld error=%s\n", length, u_errorName(errorCode));
+        printf("error in u_strToTitle(en)=%" PRId32 " error=%s\n", length, u_errorName(errorCode));
     }
     /* titlecase/Turkish */
     errorCode=U_ZERO_ERROR;
@@ -339,7 +342,7 @@ static void demoCaseMapInC() {
     if(U_SUCCESS(errorCode)) {
         printUString("full-titlecased/tr: ", buffer, length);
     } else {
-        printf("error in u_strToTitle(tr)=%ld error=%s\n", length, u_errorName(errorCode));
+        printf("error in u_strToTitle(tr)=%" PRId32 " error=%s\n", length, u_errorName(errorCode));
     }
     /* case-fold/default */
     errorCode=U_ZERO_ERROR;
@@ -347,7 +350,7 @@ static void demoCaseMapInC() {
     if(U_SUCCESS(errorCode)) {
         printUString("full-case-folded/default: ", buffer, length);
     } else {
-        printf("error in u_strFoldCase(default)=%ld error=%s\n", length, u_errorName(errorCode));
+        printf("error in u_strFoldCase(default)=%" PRId32 " error=%s\n", length, u_errorName(errorCode));
     }
     /* case-fold/Turkic */
     errorCode=U_ZERO_ERROR;
@@ -355,7 +358,7 @@ static void demoCaseMapInC() {
     if(U_SUCCESS(errorCode)) {
         printUString("full-case-folded/Turkic: ", buffer, length);
     } else {
-        printf("error in u_strFoldCase(Turkic)=%ld error=%s\n", length, u_errorName(errorCode));
+        printf("error in u_strFoldCase(Turkic)=%" PRId32 " error=%s\n", length, u_errorName(errorCode));
     }
 }
 
@@ -461,7 +464,7 @@ demoUnicodeStringStorage() {
     printUnicodeString("readonly-aliasing string after modification: ", three);
     // the aliased array is not modified
     for(i=0; i<three.length(); ++i) {
-        printf("readonly buffer[%d] after modifying its string: 0x%lx\n",
+        printf("readonly buffer[%d] after modifying its string: 0x%" PRId32 "\n",
                i, readonly[i]);
     }
     // setTo() readonly alias
@@ -483,7 +486,7 @@ demoUnicodeStringStorage() {
     // a modification writes through to the buffer
     four.setCharAt(1, 0x39);
     for(i=0; i<four.length(); ++i) {
-        printf("writeable-alias backing buffer[%d]=0x%lx "
+        printf("writeable-alias backing buffer[%d]=0x%" PRId32 " "
                "after modification\n", i, writeable[i]);
     }
     // a copy will not alias any more;
@@ -491,7 +494,7 @@ demoUnicodeStringStorage() {
     two=four;
     two.setCharAt(1, 0x21);
     for(i=0; i<two.length(); ++i) {
-        printf("writeable-alias backing buffer[%d]=0x%lx after "
+        printf("writeable-alias backing buffer[%d]=0x%" PRId32 " after "
                "modification of string copy\n", i, writeable[i]);
     }
     // setTo() writeable alias, capacity==length
@@ -503,8 +506,8 @@ demoUnicodeStringStorage() {
     one.truncate(one.length()-1);
     // we still operate on the copy
     one.setCharAt(1, 0x25);
-    printf("string after growing too much and then shrinking[1]=0x%lx\n"
-           "                          backing store for this[1]=0x%lx\n",
+    printf("string after growing too much and then shrinking[1]=0x%" PRId32 "\n"
+           "                          backing store for this[1]=0x%" PRId32 "\n",
            one.charAt(1), writeable[1]);
     // if we need it in the original buffer, then extract() to it
     // extract() does not do anything if the string aliases that same buffer
@@ -516,7 +519,7 @@ demoUnicodeStringStorage() {
     }
     one.extract(0, i, writeable);
     for(i=0; i<UPRV_LENGTHOF(writeable); ++i) {
-        printf("writeable-alias backing buffer[%d]=0x%lx after re-extract\n",
+        printf("writeable-alias backing buffer[%d]=0x%" PRId32 " after re-extract\n",
                i, writeable[i]);
     }
 }