2,499 questions
0
votes
2
answers
104
views
LAMBDA( value; value) isn't a identity function [closed]
The formula
=SPLIT("1\10/10\00002.2";"\")
doesn't result equal to
=MAP(SPLIT("1\10/10\00002.2";"\"); LAMBDA(v; v))
At the former, implicity conversion is ...
3
votes
1
answer
85
views
Failure to compile comparison expression of different typed variables [closed]
The title maybe vague because I don't know how to describe such situation.
// go 1.23.0
package main
import (
"fmt"
)
func compare(num uint16, bit uint8) bool {
// ok
return ...
Best practices
0
votes
7
replies
103
views
SPLIT without implicit conversion
I am experiencing problems with this section of my formula
=LET(
args; MAP(SPLIT("11/11"&CHAR(10)&CHAR(10)&"1"
; CHAR(10)&CHAR(10)); LAMBDA(v; TO_TEXT(v)))...
0
votes
0
answers
38
views
VS Code not printing warnings
I'm trying to set up VS Code to learn C++. I downloaded the latest version of the compiler (g++) and tried running the following simple code, which (if I understand this correctly) should print a &...
3
votes
2
answers
273
views
Why does "\0" give integer in c
So, I am learning C language and was trying to make a function that returns the length of a string. In the if statement I mistakenly used "" instead of ''. So, instead of comparing to char '\...
19
votes
2
answers
826
views
How can a longer C++ implicit conversion chain succeed and a strict subchain of it fail in operator lookup?
Background
Our original problem was that including boost::logic::tribool caused an expression of the form referenceToClass != nullptr to compile happily. We ultimately tracked this down to the ...
6
votes
1
answer
246
views
Why can my C++ class be implicitly converted in one case, but not another?
I'm getting a compiler error about a type conversion that should be legal, to my eyes.
Let's say I have a home-grown string class, convertible from and to char*:
class custom_string
{
public:
...
6
votes
3
answers
266
views
How to create a unique_ptr while guarding against implicit conversion in ctor?
Here's an example:
class Example {
public:
Example(int m, int n, double pad) {}
Example(double size, double pad) {}
};
int main() {
Example example { 1.0, 1.0 };
auto ptr = std::...
3
votes
2
answers
358
views
Unexpected null in implicit operator method
Consider this implicit operator:
public class Person
{
public Person(string name) => Name = name;
public string Name { get; }
public static implicit operator string(Person person) => ...
3
votes
2
answers
149
views
Can't copy initialize string literals for my custom datatype (class object) even when I have the constructor for that
I have a program which lets C++ support arbitrary precision numbers (very large numbers). Takes datatype as string or string literals. Basically "762...."
Compiler: g++ (Debian 10.2.1-6) 10....
5
votes
1
answer
86
views
Implicit conversion from int to union works in designated initializer but otherwise fails to compile
I have a program that maps device registers to unions of bitfields and integers. This is part of a larger code base, so although this is very C-style code, we are compiling it as C++20. Here is a ...
1
vote
1
answer
125
views
Why doesn't the conversion operator prevent ambiguity?
I have this minimal working example:
class A {
public:
A(int i) {}
A(bool b) {}
};
class B {
public:
operator int() { return 1; };
operator bool() { return false; };
operator A() { return A(...
12
votes
2
answers
407
views
How is conversion to function pointer type special that it enables implicit conversion of a callable?
This is a follow up of this question: Why can I call a callable that is const-referenced and where the actual callable is a mutable lambda?
I can mimic the implicit conversion of a const mutable ...
-5
votes
3
answers
124
views
How to fix printing declared function [duplicate]
I'm still new at functions and I tend to print the function which I don't know how to print the declared function. It prints "1" and not "John".
#include <iostream>
void ...
5
votes
2
answers
236
views
Is there a way to cast when passing arguments to a function that wants a pointer?
Take the following (common) scenario when dealing with, for example, OpenGL:
You have void glUseProgram(GLuint program);, as well as a host of other functions that all take a GLuint; but there is no ...
0
votes
4
answers
185
views
Can I check the value of the array within a two dimensional array in C
char array[8][13];
memset (&array, 0, sizeof(array));
/* this is a rough example this is in a struct that is memset */
if (array[0])
{
printf("this is valid"); /* again this code is ...
2
votes
1
answer
119
views
C++ Braced Initialization Not Triggering Expected Conversion Operator
I'm working with a C++ class that includes both a conversion operator and a constructor that takes a std::initializer_list.
According to Scott Meyers in "Effective Modern C++," Item 7, ...
2
votes
1
answer
104
views
How *actually* does this type-conversion argument-passing happen in this function call in C++
I'm trying to figure out how C++ actually breaks down the argument-passing when the formal argument is a reference and the actual argument is of a type that requires type-conversion.
Here's an ...
0
votes
1
answer
69
views
How to specify Scala 3 `scala.Conversion` when the types being converted take an arbitrary type parameter
From the Scala 3 docs on implicit conversions:
In Scala 3, an implicit conversion from type S to type T is defined by a given instance of type scala.Conversion[S, T]. For compatibility with Scala 2, ...
1
vote
0
answers
107
views
conditional operator with derived and base classes with conversion operator to built-in types issue, compiler bug?
This example:
struct X {};
struct Y : X {};
using CY = const Y;
true ? X() : CY(); // error
Which is explained in this answer, could be changed like this:
struct X { operator int() { return 0; } };
...
0
votes
2
answers
124
views
conditional operator expression with operands of std::string and c-string, how to explain result type according to the standard?
From this example:
static_assert(std::same_as<decltype(true ? std::string{} : "str"), std::string>); // compiles
You can see that result of conditional expression is prvalue of std::...
3
votes
0
answers
72
views
conditional operator: inconsistency between implicit conversion sequence used for different compilers
This is a follow-up of this question: conditional operator expression with base and const derived class doesn't compile, why?.
The core is cond ? [cv] T1() : [cv] T2() where, for instance T2 ...
6
votes
3
answers
260
views
conditional operator expression with base and const derived class doesn't compile, why?
For some reason this doesn't compile:
#include <iostream>
struct X { };
struct Y : X { };
int main() {
using CY = const Y;
true ? X() : CY(); // error: different types 'X' and 'const Y'...
1
vote
0
answers
55
views
std::string constructor not creating string from iterators [duplicate]
I'm trying to convert an std::array of integers to a string for output, so I tried using this string constructor:
template< class InputIt > basic_string( InputIt first, InputIt last, const ...
0
votes
2
answers
114
views
Integer Promotion in C
I read the c documentation but I couldn't understand it. Could you please answer my questions(Maybe my English is not good.)
I have two codes and two question.
Question about first code: Has an ...
2
votes
0
answers
60
views
Flatbuffers VectorIterator::operator- undefined behavior
I was digging into code of flatbuffers and it does seem to me that there is undefined behavior in the core library. But I just can't believe it is there (and it seems to work in some usecases)...
I'd ...
0
votes
0
answers
46
views
How to find out implicit type conversions in C# code using code analysis way
I'm trying to scan my c# project, to find out which lines have implicit type conversions, then export results to something like a xml file.
ReSharper is a probable resolution.I installed the ReSharper ...
0
votes
1
answer
59
views
rules for choosing between conversion operators
It makes sense that the assignment expression has no ambiguity. But I don't understand why the relational expression does have.
#include <iostream>
class MyClass {
public:
operator int() { ...
0
votes
1
answer
92
views
How to Handle String Numbers in from_json with Implicit Type Casting in PySpark?
I have a PySpark DataFrame schema where the quantity field is specified as IntegerType. However, when the JSON data contains a string representation of a number (e.g., "30"), the record is ...
0
votes
1
answer
91
views
In scala 3, how to implement an implicit conversion over a type refined by iron?
Here is a minimal not working example of what I am trying to do :
Let
import io.github.iltotore.iron.*
import io.github.iltotore.iron.constraint.string.*
case class User(name: String)
type Username = ...
2
votes
2
answers
174
views
What type is actually used for array indexing and pointer arithmetic in C?
If I index an array with an unsigned int or a long, is it being implicitly cast into an int, or is the type somehow maintained? If I use large unsigned int as index, is it cast into a negative int? Is ...
0
votes
1
answer
140
views
how can a standard conversion include a user-defined conversion?
I'm trying to understand the following language from cppreference.com (emphasis mine):
Each type of standard conversion sequence is assigned one of three ranks:
Exact match: no conversion required, ...
0
votes
0
answers
84
views
Warning flags for accumulation of floating-point as integers?
What warning on GCC and/or clang do I need to activate for this to give a warning?
#include<numeric>
...
std::vector<double> vec = {1.0, 2.0, 3.0};
auto const sum = std::accumulate(vec....
2
votes
0
answers
284
views
How to make gcc warn about implicit conversions from floating point to int, but not from double to float
I would like to be warned about implicit conversions from any floating point type to any integer type, but not about the narrowing conversion from double to float. E.g for this code
int main() {
...
1
vote
3
answers
138
views
Conversion operator and bool operator for if init expression
Snippet
#include <iostream>
#include <optional>
template <typename T>
struct W {
operator T&() { return *t; }
operator bool() const {
std::cout << "...
3
votes
1
answer
170
views
C++ converting constructor behavior changed in gcc 12?
I am observing a weird behavior, which I cannot explain.
The following code (a simplified version of the actual code) compiles correctly in gcc 11.4, and the argument "val" inside the read() ...
2
votes
1
answer
111
views
gcc compilation error on simple short int function call with flag -Werror=traditional-conversion
Compiling this C program with gcc 11.4.0 and -Werror=traditional-conversion raises an error:
short int f(short int x);
short int f(short int x) {
return x;
}
int main(void)
{
short int a = 0;...
13
votes
1
answer
1k
views
Seeking an explanation for the change in order of widening operations from .NET Framework 4.8 to .NET 8
We are updating our application from .NET Framework 4.8 to .NET 8.
During regression testing, we noticed that implicit widening conversions seem to happen in a different order, resulting in some ...
1
vote
1
answer
83
views
Overloaded user defined conversion operator based on value category of object selecting counter-intuitive overload
Can someone please explain which language rules are in play in the following example:
#include <iostream>
#include <type_traits>
template<typename T>
struct Holder{
T val;
...
0
votes
1
answer
95
views
Leagcy code with structs, how to do implicit conversion
I have C legacy code with structs. It looks like this:
typedef struct data
{
int a;
} data;
typedef struct user
{
data d;
} user;
data* get(user* u){return &u->d};
Now I want to ...
2
votes
3
answers
233
views
C++ reference initialization with conversion
I am trying understand the reference initialization in C++, especially for initializing lvalue reference to "const" and rvalue reference.
As I read the standard draft in here:
https://eel.is/...
0
votes
3
answers
131
views
Accessing information on a 2d array with a double pointer in a struct (C)
In trying to understand pointers, I created a M[x][y] array, a pointer to said array *p_M[x] and a pointer to said pointer **d_p_M. The first pointer points to the first element of a row in the array ...
7
votes
2
answers
158
views
GCC14 performes multiple implicit conversions instead of one matching explicit conversion
#include <cstdio>
#include <string>
class A {
std::string data;
public:
A() = default;
explicit A (const char* data) : data(data) {}
operator const char* () const;
...
2
votes
3
answers
164
views
Converting to char*** from char* [2][2]
I have the following variable
char* a[2][2] = {{"123", "456"}, {"234", "567"}};
I wanted to refer it using another variable. While the cast works, accessing ...
0
votes
2
answers
74
views
Is the & operator is essential to use as address operator [duplicate]
#include<stdio.h>
int main()
{
int a[5]={5,10,15,20,25};
int *p;
int i;
p=a;
for (i=0;i<=5;i++)
{
printf("the address of the %d is = %d\n",*p,p);
...
1
vote
1
answer
76
views
Implicit function parameter conversion not happening [duplicate]
I have the following piece of code:
template<class A>
struct X {
template<class T>
X(T t) {}
};
template<class A>
void f(X<A> x, A a) {}
int main() {
...
1
vote
1
answer
84
views
How to trigger implicit pointer conversion inline in a C macro?
Context
I have some functions to support using a custom memory allocator in my library:
void *(allocate)(struct allocator *allocator, size_t size, size_t alignment);
void (deallocate)(struct allocator ...
0
votes
1
answer
55
views
Why a stack overflow from my Scala implicit conversion?
I have an issue with my code where I'm getting a stack overflow exception when doing an implicit conversion from Calendar to PublicationSchedule. I've cut down the code and can reproduce in Scastie (...
8
votes
1
answer
91
views
Which compiler is correct for this reference initialization with user-defined conversions?
Consider:
struct A {};
struct B {
operator A&() volatile;
operator A&() const;
operator A&&();
};
B b;
const A& a = b;
(godbolt link: https://godbolt.org/z/jcYch9jdW)...
2
votes
1
answer
55
views
Do implicit and explicit transformations in C# affect real type transformations?
Why in the reference type, even if implicit conversion is done, the actual type conversion is not done even if explicit conversion is done?
While studying explicit and implicit transformations, I was ...