Skip to contentSkip to conversation

http: fix some printf format warnings on 32-bit builds

PATCH In review Ramsay Jones 7 participants 19 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 http: fix some printf format warnings on 32-bit builds

Commit f8117f55 ("http: use off_t to store partial file size", 02-11-2015) changed the type of some variables from long to off_t. The 32-bit build, which enables the large filesystem interface (_FILE_OFFSET_BITS == 64), defines the off_t type as a 64-bit integer, whereas long is a 32-bit integer. This results in a couple of printf format warnings.

In order to suppress the warnings, change the format specifier to use the PRIuMAX macro and cast the off_t argument to uintmax_t. (See also the http_opt_request_remainder() function, which uses the same solution).

---

Hi Jeff,

I don't compile on 32-bit as often as I did in the past, otherwise I would have noticed this sooner. :(

ATB,
Ramsay Jones

 http.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
http.c +4 -4
index 42f29ce..2532976 100644
@@ -1617,8 +1617,8 @@ struct http_pack_request *new_http_pack_request(
 	if (prev_posn>0) {
 		if (http_is_verbose)
 			fprintf(stderr,
-				"Resuming fetch of pack %s at byte %ld\n",
-				sha1_to_hex(target->sha1), prev_posn);
+				"Resuming fetch of pack %s at byte %"PRIuMAX"\n",
+				sha1_to_hex(target->sha1), (uintmax_t)prev_posn);
 		http_opt_request_remainder(preq->slot->curl, prev_posn);
 	}
 
@@ -1772,8 +1772,8 @@ struct http_object_request *new_http_object_request(const char *base_url,
 	if (prev_posn>0) {
 		if (http_is_verbose)
 			fprintf(stderr,
-				"Resuming fetch of object %s at byte %ld\n",
-				hex, prev_posn);
+				"Resuming fetch of object %s at byte %"PRIuMAX"\n",
+				hex, (uintmax_t)prev_posn);
 		http_opt_request_remainder(freq->slot->curl, prev_posn);
 	}
 
Signature · 1 line
2.6.0
#1 lore raw
Quoted 11 lines · Ramsay Jones

Commit f8117f55 ("http: use off_t to store partial file size", 02-11-2015) changed the type of some variables from long to off_t. The 32-bit build, which enables the large filesystem interface (_FILE_OFFSET_BITS == 64), defines the off_t type as a 64-bit integer, whereas long is a 32-bit integer. This results in a couple of printf format warnings.

In order to suppress the warnings, change the format specifier to use the PRIuMAX macro and cast the off_t argument to uintmax_t. (See also the http_opt_request_remainder() function, which uses the same solution).

I just ran across the problem when building 'next' on my Mac and was about to investigate, so am happy to find that the work has already been done. Thanks.

My machine is 64-bit, though, so perhaps it's misleading to characterize this as a fix for 32-bit builds. In particular, off_t is 'long long' on this machine, so it complains about the "long" format specifier.

Quoted 30 lines

---

http.c +4 -5
index 42f29ce..2532976 100644
@@ -1617,8 +1617,8 @@ struct http_pack_request *new_http_pack_request(
        if (prev_posn>0) {
                if (http_is_verbose)
                        fprintf(stderr,
-                               "Resuming fetch of pack %s at byte %ld\n",
-                               sha1_to_hex(target->sha1), prev_posn);
+                               "Resuming fetch of pack %s at byte %"PRIuMAX"\n",
+                               sha1_to_hex(target->sha1), (uintmax_t)prev_posn);
                http_opt_request_remainder(preq->slot->curl, prev_posn);
        }
 
@@ -1772,8 +1772,8 @@ struct http_object_request *new_http_object_request(const char *base_url,
        if (prev_posn>0) {
                if (http_is_verbose)
                        fprintf(stderr,
-                               "Resuming fetch of object %s at byte %ld\n",
-                               hex, prev_posn);
+                               "Resuming fetch of object %s at byte %"PRIuMAX"\n",
+                               hex, (uintmax_t)prev_posn);
                http_opt_request_remainder(freq->slot->curl, prev_posn);
        }
 
--

2.6.0

#2 lore raw
Quoted 14 lines · Eric Sunshine
Quoted 11 lines · Ramsay Jones

Commit f8117f55 ("http: use off_t to store partial file size", 02-11-2015) changed the type of some variables from long to off_t. The 32-bit build, which enables the large filesystem interface (_FILE_OFFSET_BITS == 64), defines the off_t type as a 64-bit integer, whereas long is a 32-bit integer. This results in a couple of printf format warnings.

In order to suppress the warnings, change the format specifier to use the PRIuMAX macro and cast the off_t argument to uintmax_t. (See also the http_opt_request_remainder() function, which uses the same solution).

Quoted 8 lines

I just ran across the problem when building 'next' on my Mac and was about to investigate, so am happy to find that the work has already been done. Thanks.

My machine is 64-bit, though, so perhaps it's misleading to characterize this as a fix for 32-bit builds. In particular, off_t is 'long long' on this machine, so it complains about the "long" format specifier.

+Lars

I wonder if 32 bit compilation can be part of travis.

#3 lore raw
Quoted 19 lines · Stefan Beller
Quoted 18 lines · Eric Sunshine
Quoted 11 lines · Ramsay Jones

Commit f8117f55 ("http: use off_t to store partial file size", 02-11-2015) changed the type of some variables from long to off_t. The 32-bit build, which enables the large filesystem interface (_FILE_OFFSET_BITS == 64), defines the off_t type as a 64-bit integer, whereas long is a 32-bit integer. This results in a couple of printf format warnings.

In order to suppress the warnings, change the format specifier to use the PRIuMAX macro and cast the off_t argument to uintmax_t. (See also the http_opt_request_remainder() function, which uses the same solution).

I just ran across the problem when building 'next' on my Mac and was about to investigate, so am happy to find that the work has already been done. Thanks.

Quoted 8 lines
Quoted 4 lines

My machine is 64-bit, though, so perhaps it's misleading to characterize this as a fix for 32-bit builds. In particular, off_t is 'long long' on this machine, so it complains about the "long" format specifier.

+Lars

I wonder if 32 bit compilation can be part of travis.

Unfortunately no. All their machines are 64-bit [1] and they have "no immediate plans to add this feature" [2]. However, we could the following build configuration on a 64-bit machine:

export CFLAGS="-m32"
export LDFLAGS="-m32"

I think then we could catch these kind of warnings. Do you see a downside with this approach?

- Lars

[1] http://docs.travis-ci.com/user/ci-environment/
[2] https://github.com/travis-ci/travis-ci/issues/986

#4 lore raw
Quoted 8 lines · Lars Schneider

Unfortunately no. All their machines are 64-bit [1] and they have "no immediate plans to add this feature" [2]. However, we could the following build configuration on a 64-bit machine:

export CFLAGS="-m32"
export LDFLAGS="-m32"

I think then we could catch these kind of warnings. Do you see a downside with this approach?

I think that should do it.

Assuming their 64 bit means x86-64 architecture, we may want to prefer -mx32, such that we can also test it?

Quoted 5 lines

- Lars

[1] http://docs.travis-ci.com/user/ci-environment/
[2] https://github.com/travis-ci/travis-ci/issues/986

#5 lore raw
In reply to Stefan Beller
Quoted 19 lines · Stefan Beller
Quoted 18 lines · Eric Sunshine
Quoted 11 lines · Ramsay Jones

Commit f8117f55 ("http: use off_t to store partial file size", 02-11-2015) changed the type of some variables from long to off_t. The 32-bit build, which enables the large filesystem interface (_FILE_OFFSET_BITS == 64), defines the off_t type as a 64-bit integer, whereas long is a 32-bit integer. This results in a couple of printf format warnings.

In order to suppress the warnings, change the format specifier to use the PRIuMAX macro and cast the off_t argument to uintmax_t. (See also the http_opt_request_remainder() function, which uses the same solution).

I just ran across the problem when building 'next' on my Mac and was about to investigate, so am happy to find that the work has already been done. Thanks.

Quoted 9 lines
Quoted 4 lines

My machine is 64-bit, though, so perhaps it's misleading to characterize this as a fix for 32-bit builds. In particular, off_t is 'long long' on this machine, so it complains about the "long" format specifier.

+Lars

I wonder if 32 bit compilation can be part of travis.

Did this warning show up on the OS X build?

ATB,
Ramsay Jones

#6 lore raw
Quoted 27 lines · Ramsay Jones
Quoted 24 lines · Stefan Beller
Quoted 22 lines · Eric Sunshine
Quoted 11 lines · Ramsay Jones

Commit f8117f55 ("http: use off_t to store partial file size", 02-11-2015) changed the type of some variables from long to off_t. The 32-bit build, which enables the large filesystem interface (_FILE_OFFSET_BITS == 64), defines the off_t type as a 64-bit integer, whereas long is a 32-bit integer. This results in a couple of printf format warnings.

In order to suppress the warnings, change the format specifier to use the PRIuMAX macro and cast the off_t argument to uintmax_t. (See also the http_opt_request_remainder() function, which uses the same solution).

I just ran across the problem when building 'next' on my Mac and was about to investigate, so am happy to find that the work has already been done. Thanks.

My machine is 64-bit, though, so perhaps it's misleading to characterize this as a fix for 32-bit builds. In particular, off_t is 'long long' on this machine, so it complains about the "long" format specifier.

Quoted 6 lines
Quoted 4 lines

+Lars

I wonder if 32 bit compilation can be part of travis.

Did this warning show up on the OS X build?

Yes, I added CFLAGS="-Werror=format" to the my experimental TravisCI build and it breaks the build on OS X. See here (you need to scroll all the way down):
https://travis-ci.org/larsxschneider/git/jobs/90899656

BTW: I tried to set "-Werror" but then I got a bunch of macro redefined errors like this:
./git-compat-util.h:614:9: error: 'strlcpy' macro redefined [-Werror]

Is this a known issue? Is this an issue at all?

Thanks,
Lars

#7 lore raw
Quoted 26 lines · Lars Schneider
Quoted 11 lines · Ramsay Jones
Quoted 10 lines · Stefan Beller
Quoted 9 lines · Eric Sunshine
Quoted 6 lines · Ramsay Jones

Commit f8117f55 ("http: use off_t to store partial file size", 02-11-2015) changed the type of some variables from long to off_t. The 32-bit build, which enables the large filesystem interface (_FILE_OFFSET_BITS == 64), defines the off_t type as a 64-bit integer, whereas long is a 32-bit integer. This results in a couple of printf format warnings.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

My machine is 64-bit, though, so perhaps it's misleading to characterize this as a fix for 32-bit builds. In particular, off_t is 'long long' on this machine, so it complains about the "long" format specifier.

I wonder if 32 bit compilation can be part of travis.

Did this warning show up on the OS X build?

Yes, I added CFLAGS="-Werror=format" to the my experimental TravisCI build and it breaks the build on OS X.
See here (you need to scroll all the way down):
https://travis-ci.org/larsxschneider/git/jobs/90899656

Quoted 4 lines

BTW: I tried to set "-Werror" but then I got a bunch of macro redefined errors like this:
./git-compat-util.h:614:9: error: 'strlcpy' macro redefined [-Werror]

Is this a known issue? Is this an issue at all?

Odd. I don't experience anything like that on my Mac.

#8 lore raw
Quoted 28 lines · Eric Sunshine
Quoted 26 lines · Lars Schneider
Quoted 11 lines · Ramsay Jones
Quoted 10 lines · Stefan Beller
Quoted 9 lines · Eric Sunshine
Quoted 6 lines · Ramsay Jones

Commit f8117f55 ("http: use off_t to store partial file size", 02-11-2015) changed the type of some variables from long to off_t. The 32-bit build, which enables the large filesystem interface (_FILE_OFFSET_BITS == 64), defines the off_t type as a 64-bit integer, whereas long is a 32-bit integer. This results in a couple of printf format warnings.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

My machine is 64-bit, though, so perhaps it's misleading to characterize this as a fix for 32-bit builds. In particular, off_t is 'long long' on this machine, so it complains about the "long" format specifier.

I wonder if 32 bit compilation can be part of travis.

Did this warning show up on the OS X build?

Yes, I added CFLAGS="-Werror=format" to the my experimental TravisCI build and it breaks the build on OS X.
See here (you need to scroll all the way down):
https://travis-ci.org/larsxschneider/git/jobs/90899656

Quoted 6 lines
Quoted 4 lines

BTW: I tried to set "-Werror" but then I got a bunch of macro redefined errors like this:
./git-compat-util.h:614:9: error: 'strlcpy' macro redefined [-Werror]

Is this a known issue? Is this an issue at all?

Odd. I don't experience anything like that on my Mac.

Could it be, that strlcpy is present on your system ? And where does it come from ?

Which OS ?
Which compiler ?
What does uname -r say ?
Do you have Macports, Fink, Brew... installed ?

#9 lore raw
Quoted 39 lines · Torsten Bögershausen
Quoted 28 lines · Eric Sunshine
Quoted 26 lines · Lars Schneider
Quoted 11 lines · Ramsay Jones
Quoted 10 lines · Stefan Beller
Quoted 9 lines · Eric Sunshine
Quoted 6 lines · Ramsay Jones

Commit f8117f55 ("http: use off_t to store partial file size", 02-11-2015) changed the type of some variables from long to off_t. The 32-bit build, which enables the large filesystem interface (_FILE_OFFSET_BITS == 64), defines the off_t type as a 64-bit integer, whereas long is a 32-bit integer. This results in a couple of printf format warnings.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

My machine is 64-bit, though, so perhaps it's misleading to characterize this as a fix for 32-bit builds. In particular, off_t is 'long long' on this machine, so it complains about the "long" format specifier.

I wonder if 32 bit compilation can be part of travis.

Did this warning show up on the OS X build?

Yes, I added CFLAGS="-Werror=format" to the my experimental TravisCI build and it breaks the build on OS X.
See here (you need to scroll all the way down):
https://travis-ci.org/larsxschneider/git/jobs/90899656

Quoted 6 lines
Quoted 4 lines

BTW: I tried to set "-Werror" but then I got a bunch of macro redefined errors like this:
./git-compat-util.h:614:9: error: 'strlcpy' macro redefined [-Werror]

Is this a known issue? Is this an issue at all?

Odd. I don't experience anything like that on my Mac.

Quoted 8 lines

Could it be, that strlcpy is present on your system ? And where does it come from ?

Which OS ?
Which compiler ?
What does uname -r say ?
Do you have Macports, Fink, Brew... installed ?

Looks like this is a OS X only issue. Happens with clang and gcc on the OS X Mavericks TravisCI machines [1]:
https://travis-ci.org/larsxschneider/git/jobs/90919078
https://travis-ci.org/larsxschneider/git/jobs/90919080

On Linux+gcc the following error happens if "-Werror" is present:
https://travis-ci.org/larsxschneider/git/jobs/90919076
Do you have an idea what that might be?

Linux+clang works fine:
https://travis-ci.org/larsxschneider/git/jobs/90919074

- Lars

[1] http://docs.travis-ci.com/user/ci-environment/

#10 lore raw
In reply to Eric Sunshine
Quoted 28 lines · Eric Sunshine
Quoted 26 lines · Lars Schneider
Quoted 11 lines · Ramsay Jones
Quoted 10 lines · Stefan Beller
Quoted 9 lines · Eric Sunshine
Quoted 6 lines · Ramsay Jones

Commit f8117f55 ("http: use off_t to store partial file size", 02-11-2015) changed the type of some variables from long to off_t. The 32-bit build, which enables the large filesystem interface (_FILE_OFFSET_BITS == 64), defines the off_t type as a 64-bit integer, whereas long is a 32-bit integer. This results in a couple of printf format warnings.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

My machine is 64-bit, though, so perhaps it's misleading to characterize this as a fix for 32-bit builds. In particular, off_t is 'long long' on this machine, so it complains about the "long" format specifier.

I wonder if 32 bit compilation can be part of travis.

Did this warning show up on the OS X build?

Yes, I added CFLAGS="-Werror=format" to the my experimental TravisCI build and it breaks the build on OS X.
See here (you need to scroll all the way down):
https://travis-ci.org/larsxschneider/git/jobs/90899656

Quoted 7 lines
Quoted 4 lines

BTW: I tried to set "-Werror" but then I got a bunch of macro redefined errors like this:
./git-compat-util.h:614:9: error: 'strlcpy' macro redefined [-Werror]

Is this a known issue? Is this an issue at all?

Odd. I don't experience anything like that on my Mac.

Hmm, from the output, it looks like the configure script is not detecting that 'strlcpy' is available (so setting NO_STRLCPY=YesPlease in the config.mak.autogen file). However, it seems to be a 'macro redirect' set in the /usr/include/secure/_string.h header file (presumably it redirects between a more or less secure version ;-)

Unfortunately, I don't have access to a mac - so I can't help you with the debugging. :(

ATB,
Ramsay Jones

#11 lore raw
Quoted 46 lines · Ramsay Jones
Quoted 28 lines · Eric Sunshine
Quoted 26 lines · Lars Schneider
Quoted 11 lines · Ramsay Jones
Quoted 10 lines · Stefan Beller
Quoted 9 lines · Eric Sunshine
Quoted 6 lines · Ramsay Jones

Commit f8117f55 ("http: use off_t to store partial file size", 02-11-2015) changed the type of some variables from long to off_t. The 32-bit build, which enables the large filesystem interface (_FILE_OFFSET_BITS == 64), defines the off_t type as a 64-bit integer, whereas long is a 32-bit integer. This results in a couple of printf format warnings.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

My machine is 64-bit, though, so perhaps it's misleading to characterize this as a fix for 32-bit builds. In particular, off_t is 'long long' on this machine, so it complains about the "long" format specifier.

I wonder if 32 bit compilation can be part of travis.

Did this warning show up on the OS X build?

Yes, I added CFLAGS="-Werror=format" to the my experimental TravisCI build and it breaks the build on OS X.
See here (you need to scroll all the way down):
https://travis-ci.org/larsxschneider/git/jobs/90899656

Quoted 7 lines
Quoted 4 lines

BTW: I tried to set "-Werror" but then I got a bunch of macro redefined errors like this:
./git-compat-util.h:614:9: error: 'strlcpy' macro redefined [-Werror]

Is this a known issue? Is this an issue at all?

Odd. I don't experience anything like that on my Mac.

Hmm, from the output, it looks like the configure script is not detecting that 'strlcpy' is available (so setting NO_STRLCPY=YesPlease in the config.mak.autogen file). However, it seems to be a 'macro redirect' set in the /usr/include/secure/_string.h header file (presumably it redirects between a more or less secure version ;-)

Quoted 3 lines

Unfortunately, I don't have access to a mac - so I can't help you with the debugging. :(

I don't have any experience with autotools at all. However, here is what I found out on OS X Mavericks (10.9.5):
1.) In config.mak.uname, line 103, "NO_STRLCPY = YesPlease" is set for some old OS X version. However, it looks like these settings have no impact at all. 2.) In configure.ac, line 1010, the AC_CHECK_FUNC macros (via GIT_CHECK_FUNC) is used to detect strlcpy. That detection fails on OS X Mavericks. 3.) I tried to use "AC_CHECK_DECLS" to detect strlcpy declarations on OS X and this works.

Can you give me a few hints how to debug this further? Why do have the values in config.mak.uname no impact? My idea was to detect OS X Mavericks there and unset NO_STRLCPY. Could that work?

Thanks,
Lars

#12 lore raw
In reply to Eric Sunshine
Quoted 9 lines · Eric Sunshine
Quoted 7 lines · Ramsay Jones

Commit f8117f55 ("http: use off_t to store partial file size", 02-11-2015) changed the type of some variables from long to off_t. The 32-bit build, which enables the large filesystem interface (_FILE_OFFSET_BITS == 64), defines the off_t type as a 64-bit integer, whereas long is a 32-bit integer. This results in a couple of printf format warnings.

Quoted 8 lines
Quoted 4 lines

In order to suppress the warnings, change the format specifier to use the PRIuMAX macro and cast the off_t argument to uintmax_t. (See also the http_opt_request_remainder() function, which uses the same solution).

I just ran across the problem when building 'next' on my Mac and was about to investigate, so am happy to find that the work has already been done. Thanks.

Hmm, interesting. I've never used a Mac, so please forgive my ignorance ...

Quoted 4 lines

My machine is 64-bit, though, so perhaps it's misleading to characterize this as a fix for 32-bit builds. In particular, off_t is 'long long' on this machine, so it complains about the "long" format specifier.

... but this seems to imply that sizeof(long) is 4 on your machine, right? (on x86_64 linux it's 8, which is why I hadn't noticed before).

Jeff, do you need me to re-word the commit message?

ATB,
Ramsay Jones

Quoted 32 lines
Quoted 31 lines

---

http.c +4 -5
index 42f29ce..2532976 100644
@@ -1617,8 +1617,8 @@ struct http_pack_request *new_http_pack_request(
        if (prev_posn>0) {
                if (http_is_verbose)
                        fprintf(stderr,
-                               "Resuming fetch of pack %s at byte %ld\n",
-                               sha1_to_hex(target->sha1), prev_posn);
+                               "Resuming fetch of pack %s at byte %"PRIuMAX"\n",
+                               sha1_to_hex(target->sha1), (uintmax_t)prev_posn);
                http_opt_request_remainder(preq->slot->curl, prev_posn);
        }
 
@@ -1772,8 +1772,8 @@ struct http_object_request *new_http_object_request(const char *base_url,
        if (prev_posn>0) {
                if (http_is_verbose)
                        fprintf(stderr,
-                               "Resuming fetch of object %s at byte %ld\n",
-                               hex, prev_posn);
+                               "Resuming fetch of object %s at byte %"PRIuMAX"\n",
+                               hex, (uintmax_t)prev_posn);
                http_opt_request_remainder(freq->slot->curl, prev_posn);
        }
 
--

2.6.0

#13 lore raw
Quoted 10 lines · Ramsay Jones
Quoted 6 lines · Eric Sunshine

On Tue, Nov 10, 2015 at 7:23 PM, Ramsay Jones <[email protected]> wrote:
My machine is 64-bit, though, so perhaps it's misleading to characterize this as a fix for 32-bit builds. In particular, off_t is 'long long' on this machine, so it complains about the "long" format specifier.

... but this seems to imply that sizeof(long) is 4 on your machine, right? (on x86_64 linux it's 8, which is why I hadn't noticed before).

This code on my Mac:

    printf("sizeof(long)=%zu\n", sizeof(long));
    printf("sizeof(long long)=%zu\n", sizeof(long long));
    printf("sizeof(off_t)=%zu\n", sizeof(off_t));

produces:

    sizeof(long)=8
    sizeof(long long)=8
    sizeof(off_t)=8

The fact that 'long' and 'long long' happen to be the same size (in this case) is immaterial. What is important is that the code is just wrong to be using the "%l" specifier for 'long' when the actual datatype is 'long long' (which is what 'off_t' is under-the-hood in this case).

#14 lore raw
Quoted 5 lines · Eric Sunshine

The fact that 'long' and 'long long' happen to be the same size (in this case) is immaterial. What is important is that the code is just wrong to be using the "%l" specifier for 'long' when the actual datatype is 'long long' (which is what 'off_t' is under-the-hood in this case).

Right. We cannot assume anything about what is in off_t, and should be casting to uintmax_t. So the patch is right, but I agree the commit message could be better. I started to hack it up myself, but I didn't want to put too many words in Ramsay's mouth. Do you mind resending with an updated commit message?

Thanks (and thank you in the first place for finding and fixing the breakage I introduced in f8117f55).

-Peff

#15 lore raw
In reply to Eric Sunshine
Quoted 25 lines · Eric Sunshine
Quoted 10 lines · Ramsay Jones
Quoted 6 lines · Eric Sunshine

On Tue, Nov 10, 2015 at 7:23 PM, Ramsay Jones <[email protected]> wrote:
My machine is 64-bit, though, so perhaps it's misleading to characterize this as a fix for 32-bit builds. In particular, off_t is 'long long' on this machine, so it complains about the "long" format specifier.

... but this seems to imply that sizeof(long) is 4 on your machine, right? (on x86_64 linux it's 8, which is why I hadn't noticed before).

This code on my Mac:

    printf("sizeof(long)=%zu\n", sizeof(long));
    printf("sizeof(long long)=%zu\n", sizeof(long long));
    printf("sizeof(off_t)=%zu\n", sizeof(off_t));

produces:

    sizeof(long)=8
    sizeof(long long)=8
    sizeof(off_t)=8
Quoted 5 lines

The fact that 'long' and 'long long' happen to be the same size (in this case) is immaterial. What is important is that the code is just wrong to be using the "%l" specifier for 'long' when the actual datatype is 'long long' (which is what 'off_t' is under-the-hood in this case).

Ah. OK, so %ld for long and %lld for long long, I suppose.

Hmm, not that it matters, but I wonder what the PRId64 macro is. ;-)

ATB,
Ramsay Jones

#16 lore raw
Quoted 1 line

Ah. OK, so %ld for long and %lld for long long, I suppose. Only if you have a system that's support it.

Linux does, Windows not.

Quoted 1 line

Hmm, not that it matters, but I wonder what the PRId64 macro is. ;-)

It's "I64d" for Windows, and "lld" for all Gnu based systems and others,

When you do printf("%lld %ld", long_long_var, long_var),
the "printf runtime" under Windows will treat "%lld" as "%ld", and print the lower part of long_long_var.
And will not pull a long long from stack, but a long, resulting i all kinds of confusion

So whenever a long long is printed, I can warmly recommend to use

PRId64

#17 lore raw
Quoted 4 lines · Torsten Bögershausen
Quoted 1 line

Ah. OK, so %ld for long and %lld for long long, I suppose.

Only if you have a system that's support it.

Linux does, Windows not.

Sure, but I was speculating specifically about Eric's mac (which I have no experience with).

Quoted 3 lines
Quoted 2 lines

Hmm, not that it matters, but I wonder what the PRId64 macro is. ;-)

It's "I64d" for Windows, and "lld" for all Gnu based systems and others,

[On Gnu systems, I believe it is %lld on 32-bit and %ld on 64-bit.]

Again, I was commenting on Eric's mac, which _seems_ to allow the use of both %ld and %lld when printing 64-bit integers, so which does it choose for PRId64 ...

Quoted 9 lines

When you do printf("%lld %ld", long_long_var, long_var),
the "printf runtime" under Windows will treat "%lld" as "%ld", and print the lower part of long_long_var.
And will not pull a long long from stack, but a long, resulting i all kinds of confusion

So whenever a long long is printed, I can warmly recommend to use

PRId64

Indeed.

ATB,
Ramsay Jones

#18 lore raw
In reply to Torsten Bögershausen
Quoted 3 lines · Torsten Bögershausen

So whenever a long long is printed, I can warmly recommend to use

PRId64

PRId64 is not suitable for long long, only for int64_t.

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."