Skip to content

Instantly share code, notes, and snippets.

@schwehr
Created February 5, 2023 17:41
Show Gist options
  • Save schwehr/722e4c5147f155905502f7173ef3089f to your computer and use it in GitHub Desktop.
Save schwehr/722e4c5147f155905502f7173ef3089f to your computer and use it in GitHub Desktop.
Exploring issues around xdr_int and xdr_long in hdf4 putget.c
// SPDX-License-Identifier: Apache-2.0
// Copyright 2023 Google Inc. All Rights Reserved.
/*
https://www.shrubbery.net/solaris9ab/SUNWdev/SOL64TRANS/p16.html
_LP64
The _LP64 feature test macro is used to specify the LP64 data model where ints
are 32 bit quantities and longs and pointers are 64 bit quantities.
_LP64 is defined by default when compiling in 64-bit mode (-xarch=v9).
Other than making sure that either <sys/types.h> or <sys/isa_defs.h> is
included in source in order to make visible the _LP64 definition, the
developer needs to do nothing else.
locally on x86 64 debian testing
https://stackoverflow.com/questions/20462091/what-definitions-exist-like-lp64-and-arm64-in-cocoa-that-differentiate-p
clang -dM -E -x c /dev/null | grep LP64
#define _LP64 1
#define __LP64__ 1
*/
// blaze test -c opt --test_output=streamed --config=arm //experimental/users/schwehr/cpp/hdf4:lp64_test
// blaze test -c dbg --test_output=streamed --config=arm //experimental/users/schwehr/cpp/hdf4:lp64_test
// blaze test --test_output=streamed --config=arm //experimental/users/schwehr/cpp/hdf4:lp64_test
#include <climits>
#include <cstdint>
#include <iostream>
#include <typeinfo>
// #include "testing/base/public/gmock.h"
#include "testing/base/public/gunit.h"
namespace {
// #if LONG_MAX == INT64_MAX
// #define H4_HAVE_LP64
// #endif
#if LONG_MAX == INT64_MAX
constexpr bool H4_HAVE_LP64 = true;
#else
constexpr bool H4_HAVE_LP64 = true;
#endif
// Works for both arm and x86 64
TEST(PlatformTest, Lp64) {
EXPECT_EQ(4, sizeof(int));
EXPECT_EQ(8, sizeof(long));
EXPECT_EQ(8, sizeof(int64_t));
EXPECT_EQ(9223372036854775807, LONG_MAX);
EXPECT_EQ(9223372036854775807, INT64_MAX);
EXPECT_TRUE(LONG_MAX == INT64_MAX);
EXPECT_TRUE(H4_HAVE_LP64);
#ifdef __aarch64__
EXPECT_EQ(1, __aarch64__);
#endif
#ifdef __x86_64__
EXPECT_EQ(1, __x86_64__);
#endif
// I do not have shell access to run the target, so use stderr from test.
// const std::type_info& type_int = typeid(int);
const auto &type_int = typeid(int);
const auto &type_int64_t = typeid(int64_t);
const auto &type_long = typeid(long);
std::cerr << "typeid(int): " <<type_int.name() << "\n"; // i
std::cerr << "typeid(int64_t): " <<type_int64_t.name() << "\n"; // l
std::cerr << "typeid(long): " <<type_long.name() << "\n"; // l
// Not sure how to make this work
// https://en.cppreference.com/w/cpp/language/typeid
// std::cerr << "int" << typeid(int)::name() << "\n";
// std::cerr << "long" << typeid(long)::name() << "\n";
// std::cerr << "int64_t" << typeid(int64_t)::name() << "\n";
// This issue is around this in putget.c
// return (xdr_int(xdrs, (nclong *)values));
// return (xdr_long(xdrs, (nclong *)values));
}
} // namespace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment