Wednesday, October 5, 2022

Digest for comp.lang.c++@googlegroups.com - 17 updates in 4 topics

Lynn McGuire <lynnmcguire5@gmail.com>: Oct 04 08:41PM -0500

How do I specify an 8 byte bool ? Long long ?
 
Thanks,
Lynn
Keith Thompson <Keith.S.Thompson+u@gmail.com>: Oct 04 07:58PM -0700

> How do I specify an 8 byte bool ? Long long ?
 
What for?
 
bool is a predefined type, and its size is determined by the implementation.
 
long long is at least 64 bits (and almost always exactly 64 bits).
uint64_t and int64_t are exactly 64 bits, but are not guaranteed to
exist. A "byte" is almost always 8 bits, but may be larger (see
CHAR_BIT).
 
What problem are you trying to solve?
 
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */
Lynn McGuire <lynnmcguire5@gmail.com>: Oct 04 10:35PM -0500

On 10/4/2022 9:58 PM, Keith Thompson wrote:
> exist. A "byte" is almost always 8 bits, but may be larger (see
> CHAR_BIT).
 
> What problem are you trying to solve?
 
I've got a double array, integer*8 array, logical*8 array, and
character*8 array equivalenced in my Fortran code that I am converting
to C++. I want to have the same capability in my C++ code until I get
down the road and figure out what I want to do with this code, if anything.
 
Thanks,
Lynn
Christian Gollwitzer <auriocus@gmx.de>: Oct 05 07:38AM +0200

Am 05.10.22 um 05:35 schrieb Lynn McGuire:
> character*8 array equivalenced in my Fortran code that I am converting
> to C++.  I want to have the same capability in my C++ code until I get
> down the road and figure out what I want to do with this code, if anything.
 
Then I'd use uint64_t for the logical, int64_t for the integer and
char[8] for the character array (not sure about the last one, though,
since I don't use Fortran much). You can also check how the old f2c
converter compiles it (https://netlib.org/f2c/). It generally works well
for F77 code, although the output is not overly readable.
I guess you used fable instead of f2c because you want to work on the
code after translation, right?
 
Christian
David Brown <david.brown@hesbynett.no>: Oct 05 09:38AM +0200

On 05/10/2022 05:35, Lynn McGuire wrote:
> down the road and figure out what I want to do with this code, if anything.
 
> Thanks,
> Lynn
 
I don't know Fortran, but if you want something that works like a bool
and takes 8 bytes, you can either use a uint64_t and be careful that you
don't put anything other than 0 or 1 in it (that might be fine when you
have automatically generated code).
 
Alternatively, it's easy to make a class that acts like a bool:
 
(Adding concepts to limit the type of T is left as an exercise for the
reader :-) )
 
 
#include <cstdint>
 
template <class T>
class sized_bool {
private :
T storage;
public :
constexpr sized_bool() : storage(0) {}
constexpr sized_bool(bool b) : storage(b) {}
constexpr operator bool() const { return storage; }
};
 
using big_bool = sized_bool<std::uint64_t>;
 
void tests() {
static_assert(sizeof(big_bool) == 8);
 
constexpr big_bool b1 = 1;
static_assert(b1 == true);
static_assert(b1 == 1);
static_assert(b1 ? 1 : 0);
 
constexpr big_bool b2 { false };
static_assert(b2 == false);
static_assert(b2 == 0);
static_assert(b2 ? 0 : 1);
 
constexpr big_bool b3 = 123;
static_assert(b3 == true);
static_assert(b3 == 1);
static_assert(b3 ? 1 : 0);
 
static_assert(big_bool(100) == 1);
}
Lynn McGuire <lynnmcguire5@gmail.com>: Oct 05 02:02PM -0500

On 10/5/2022 12:38 AM, Christian Gollwitzer wrote:
> I guess you used fable instead of f2c because you want to work on the
> code after translation, right?
 
>             Christian
 
I am building my own version of f2c with significant code from fable.
Fable is written in python and is part of another app so separating it
out is a "Hot Skillz". F2c is written in very nasty plain old C code.
 
Here is my task list for f2c to date:
 
// 1. added support for a .cpp output file instead of just the .c file
// 2. convert the F90 cycle command to the C continue
// 3. convert the F90 exit command to the C break
// 4. convert the c /* comment */ to // comment
// 5. added support for the logical*8 data type, complementary to the
integer*8
// data type for memory alignment, both resolve to the C long long
integer
// 6. generate true and false for logicals if C++ instead of TRUE_ and
FALSE_
// 7. removed all trailing underscores from variable and subroutine names
// 8. removed the ftnlen argument from the calls to subroutines with
character arguements
// 9. added the Fabel FEM library
 
 
// Things to do:
// 1. make all argument arrays start at index 0
// 2. convert writes to the FEM single command write with embedded format
// 3. retain array lengths
// 4. retain parameters with their values
 
Lynn
Lynn McGuire <lynnmcguire5@gmail.com>: Oct 05 02:03PM -0500

On 10/5/2022 12:38 AM, Christian Gollwitzer wrote:
> I guess you used fable instead of f2c because you want to work on the
> code after translation, right?
 
>             Christian
 
BTW, thanks !
 
Lynn
Lynn McGuire <lynnmcguire5@gmail.com>: Oct 05 02:03PM -0500

On 10/5/2022 2:38 AM, David Brown wrote:
>     static_assert(b3 ? 1 : 0);
 
>     static_assert(big_bool(100) == 1);
> }
 
Thanks !
 
Lynn
Lynn McGuire <lynnmcguire5@gmail.com>: Oct 05 02:10PM -0500

On 10/4/2022 8:41 PM, Lynn McGuire wrote:
> How do I specify an 8 byte bool ?  Long long ?
 
> Thanks,
> Lynn
 
I forgot to mention that this is how I handle the 8 byte logical*8 right
now:
 
typedef long long logical8;
 
Thanks,
Lynn
scott@slp53.sl.home (Scott Lurndal): Oct 05 08:34PM


>I forgot to mention that this is how I handle the 8 byte logical*8 right
>now:
 
>typedef long long logical8;
 
Wouldn't it make more sense to convert to LOGICAL*4 or just LOGICAL and
use a byte-width C++ bool instead? Seems silly to waste 63 bits.
Lynn McGuire <lynnmcguire5@gmail.com>: Oct 05 04:18PM -0500

On 10/5/2022 3:34 PM, Scott Lurndal wrote:
 
>> typedef long long logical8;
 
> Wouldn't it make more sense to convert to LOGICAL*4 or just LOGICAL and
> use a byte-width C++ bool instead? Seems silly to waste 63 bits.
 
The indexes for the arrays are the same value for all four types of
arrays. So every array chunk has to be 64 bits whether it is double,
integer*8, character*8, or logical*8.
 
And yes, I agree, not efficient. But, who cares in this day of TB
drives and GB ram ? And I want to use the same code base for the 32 bit
version and the 64 bit version.
 
Thanks,
Lynn
"Fred. Zwarts" <F.Zwarts@KVI.nl>: Oct 05 11:19PM +0200

Op 05.okt..2022 om 05:35 schreef Lynn McGuire:
> character*8 array equivalenced in my Fortran code that I am converting
> to C++.  I want to have the same capability in my C++ code until I get
> down the road and figure out what I want to do with this code, if anything.
 
The Fortran EQUIVALENT is in my mind roughly equivalent to a C++ union.
So, I would probably go for an array of unions. Where each union is a
union of a double, integer, bool and char[8]. The bool would then
automatically use the space of the largest type in the union.
scott@slp53.sl.home (Scott Lurndal): Oct 05 10:25PM


>The indexes for the arrays are the same value for all four types of
>arrays. So every array chunk has to be 64 bits whether it is double,
>integer*8, character*8, or logical*8.
 
Presumably the compiler will do the appropriate math using
the index to calculate the memory byte(s) required.
 
I don't understand your comment, unless you're using byte offsets
intead of normal fortran indexing.
scott@slp53.sl.home (Scott Lurndal): Oct 05 10:27PM

>the index to calculate the memory byte(s) required.
 
>I don't understand your comment, unless you're using byte offsets
>intead of normal fortran indexing.
 
Ah never mind, I see your aliasing the same storage four ways.
Jivanmukta <jivanmukta@poczta.onet.pl>: Oct 05 09:42AM +0200

W dniu 4.10.2022 o 08:02, Juha Nieminen pisze:
> whether there is an actual problem or whether the debugger you are
> using is just flawed. Thus, we will never know (unless someone goes
> through the trouble of combing through the code you did post).
 
I have a problem with preparing minimal complete program: I extracted
problematic code to new test project and I simplified Makefile, but test
project works fine.
 
test/src/test.cpp:
 
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <stdlib.h>
 
int main() {
std::vector<std::wstring> vendor_frameworks_dirs = { L"this is a
test" };
for (auto dir = vendor_frameworks_dirs.begin(); dir !=
vendor_frameworks_dirs.end(); ++dir)
{
std::string s = std::string((*dir).begin(), (*dir).end());
std::cout << s;
}
return 0;
}
 
test/Makefile:
 
ObjSuf = o
SrcSuf = cpp
DllSuf = so
BUILD := ./build
OBJ_DIR := $(BUILD)/objects
APP_DIR := $(BUILD)/apps
INCLUDE := -Iinclude # -I src/boost_1_65_0
CXXFLAGS := -Wall -Wextra -Werror -no-pie -D_X86_=1 # -std=c++17
-fpermissive -pedantic-errors; add "-no-pie" to the CMAKE_CXX_FLAGS
LDFLAGS := -lstdc++ -lm -lstdc++fs -L/usr/lib # -Lsrc/boost_1_65_0/lib/
-lboost_regex-gcc34-mt-d-1_3
TARGET := test
 
all: build $(APP_DIR)/$(TARGET)
$(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -o $@ $(LDFLAGS)
SRC := $(wildcard src/*.$(SrcSuf))
OBJECTS := $(SRC:%.$(SrcSuf)=$(OBJ_DIR)/%.$(ObjSuf))
 
$(OBJ_DIR)/%.$(ObjSuf): %.$(SrcSuf)
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -o $@ $(LDFLAGS)
 
$(APP_DIR)/$(TARGET): $(OBJECTS)
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) -o $(APP_DIR)/$(TARGET) $^ $(LDFLAGS)
 
PHONY: all build clean debug release
 
debug: CXXFLAGS += -DDEBUG -g -O0 -fsanitize=address -D_GLIBCXX_DEBUG #
-static-libasan
debug: all
 
test: CXXFLAGS += -pg # dynamic execution profiler
test: all
 
release: CXXFLAGS += -O2
release: all # production
 
clean:
-@rm -rvf $(OBJ_DIR)/*
-@rm -rvf $(APP_DIR)/*
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Oct 04 08:27PM -0700

On 5/12/2022 12:16 PM, Chris M. Thomasson wrote:
> Using my experimental vector field to generate a fractal formation. Here
> is generation two:
 
> https://fractalforums.org/gallery/1612-120522191048.png
 
Another vector field experiment using min distance orbits from Julia
sets, all in C++:
 
https://fractalforums.org/gallery/1612-051022032409.png
Manfred <noname@add.invalid>: Oct 05 02:54AM +0200

On 10/4/2022 1:47 PM, Bo Persson wrote:
 
> My (non-language-lawyer) interpretation is that since f and its local
> foo don't depend on the template parameter T, they should be looked up
> immediately, and not at the point of instantiation.
 
A good example of when someone's question, and its answer, are useful
for someone else too.
Thanks.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: