pointers

Workaround on declaring a unsafe fixed custom struct array?

徘徊边缘 提交于 2021-01-22 05:19:25
问题 Is there any workaround for the error CS1663 ("Fixed size buffer type must be one of the following: bool, byte, short, int, long, char, sbyte, ushort, uint, ulong, float or double.")? I need to declare a unsafe fixed array from another blittable custom type struct but I'm stuck in this compiler error. Showing some code to elucidate the problem below. struct s1 { byte _b1; byte _b2; } unsafe struct s2 { fixed s1 _s1[5]; // CS1663 here... } Note that the two structs are blittable, so the error

Workaround on declaring a unsafe fixed custom struct array?

风格不统一 提交于 2021-01-22 05:19:03
问题 Is there any workaround for the error CS1663 ("Fixed size buffer type must be one of the following: bool, byte, short, int, long, char, sbyte, ushort, uint, ulong, float or double.")? I need to declare a unsafe fixed array from another blittable custom type struct but I'm stuck in this compiler error. Showing some code to elucidate the problem below. struct s1 { byte _b1; byte _b2; } unsafe struct s2 { fixed s1 _s1[5]; // CS1663 here... } Note that the two structs are blittable, so the error

What does *(*int)(nil) = 0 mean in golang?

萝らか妹 提交于 2021-01-21 06:42:08
问题 I notice there is one line *(*int)(nil) = 0 in function throw //go:nosplit func throw(s string) { // Everything throw does should be recursively nosplit so it // can be called even when it's unsafe to grow the stack. systemstack(func() { print("fatal error: ", s, "\n") }) gp := getg() if gp.m.throwing == 0 { gp.m.throwing = 1 } fatalthrow() *(*int)(nil) = 0 // not reached } What does *(*int)(nil) = 0 means? and since this line *(*int)(nil) = 0 could NOT be reached, why it is here? any special

using non-smart pointers in modern C++

Deadly 提交于 2021-01-21 04:31:26
问题 Short Version: Is there any acceptable reason for using non-smart pointers in modern C++? Long Version: we have a huge product that contains lot's of old C++ code and now we are trying to refactor it to the modern C++ era. Along with all the old fashioned code, there is huge amount of pointers passing around (mostly with SAL annotations to provide some sense of security) and I was wondering if we should change all of them to smart pointers or maybe leave some of them as is? Trying to convert

using non-smart pointers in modern C++

时光怂恿深爱的人放手 提交于 2021-01-21 04:31:07
问题 Short Version: Is there any acceptable reason for using non-smart pointers in modern C++? Long Version: we have a huge product that contains lot's of old C++ code and now we are trying to refactor it to the modern C++ era. Along with all the old fashioned code, there is huge amount of pointers passing around (mostly with SAL annotations to provide some sense of security) and I was wondering if we should change all of them to smart pointers or maybe leave some of them as is? Trying to convert

What is the difference between: Handle, Pointer and Reference

99封情书 提交于 2021-01-20 14:15:33
问题 How does a handle differ from a pointer to an object and also why can't we have a reference to a reference? 回答1: A handle is usually an opaque reference to an object. The type of the handle is unrelated to the element referenced. Consider for example a file descriptor returned by open() system call. The type is int but it represents an entry in the open files table. The actual data stored in the table is unrelated to the int that was returned by open() freeing the implementation from having

Using a struct vs a pointer to a struct

最后都变了- 提交于 2021-01-20 09:12:22
问题 I was working on the following as an example to see the differences between passing an object directly and then passing a pointer to it: #include "stdio.h" // Car object typedef struct Car { char* name; unsigned int price; } Car; void print_car(Car car) { printf("<Car: %s, Price: $%d>", car.name, car.price); }; void print_car2(Car *car) { printf("<Car: %s, Price: $%d>", car->name, car->price); }; int main(int argc, char* argv[]) { Car chevy = {chevy.name = "Chevy", chevy.price = 45000}; print

Using a struct vs a pointer to a struct

狂风中的少年 提交于 2021-01-20 09:11:33
问题 I was working on the following as an example to see the differences between passing an object directly and then passing a pointer to it: #include "stdio.h" // Car object typedef struct Car { char* name; unsigned int price; } Car; void print_car(Car car) { printf("<Car: %s, Price: $%d>", car.name, car.price); }; void print_car2(Car *car) { printf("<Car: %s, Price: $%d>", car->name, car->price); }; int main(int argc, char* argv[]) { Car chevy = {chevy.name = "Chevy", chevy.price = 45000}; print

Compiler error: invalid conversion from 'int' to 'int*' [-fpermissive]|

。_饼干妹妹 提交于 2021-01-19 06:39:07
问题 I got a compiler error: main.cpp|59|error: invalid conversion from 'int' to 'int*' [-fpermissive]| The offending line is int *pComienzo = vector, *pFinal = vector[nElementos-1]; Why there is an error? Can someone help me? Below is my code: #include <iostream> #include <ctype.h> using namespace std; const unsigned short int MAX_VAL = 10; int LongitudCadena(char*); int BuscarCaracter(char *cadena, char caracter); void Ordenar(int *vector, int nElementos, bool ascendente); int main() { char

Is C++ Array passed by reference or by pointer?

ぐ巨炮叔叔 提交于 2021-01-18 06:00:13
问题 In school, our lecturer taught us that the entire array was passed by reference when we pass it to a function,. However, recently I read a book. It says that arrays are passed by pointer by default when passing the entire array to a function. The book further mention that " passing by pointer is very similar to passing by reference ", which means that passing by pointer and passing by reference are actually different. It appears that different source stated differently. So my question is: In