pointers

Find all variables that point to the same memory in Visual Studio

拈花ヽ惹草 提交于 2021-02-11 14:25:12
问题 In Visual Studio 2008, is there a way of finding all the variables that point to the same object as another variable? So in the example below I would want to find out that ref1 and ref2 both point to the same object as original . var original = new List<string>() { "Some Data" }; var ref1 = original; var ref2 = ref1; Essentially I want to be able to call ReferenceEquals() on all the variables in memory and then see all the ones that are equal. Except I want to be able to do this in the VS2008

Read integers from a specific line from a file in c

一笑奈何 提交于 2021-02-11 13:55:30
问题 Hello there I've been struggling with this problem for some time and after some research on the internet that didn't bear any fruit I decided to ask for some help. I need to read some integers from a file and from a specific line and then do something with them. I know this trick for handling strings of characters while(fgets(pointer_to_string, length, "file_name.txt")) line++; /*increment line-integer type- by 1*/ if(line == your_line) /*do something with the strings at that line*/ I know

Creating instance in an another class of an object

三世轮回 提交于 2021-02-11 12:54:24
问题 I need to create an instance in class Crop of Plant class and i cant manage to find a way to make that work. Hope you guys can help at that. This my main where i'm sending an object to the class crop. int main(){ char select = 'a'; int plant_num = 2; int crop_num = 0; Crop crop[10]; Plant plant[20]; plant[0] = Plant("Carrots",'c'); plant[1] = Plant("Lettuce",'l'); plant[2] = Plant("Rosemary",'r'); crop[0] = Crop(plant[0],4,2); crop_num++; cout << "Garden Designer" << endl; cout << "==========

C change the value a void pointer represents

一曲冷凌霜 提交于 2021-02-11 12:41:48
问题 This is a follow up to this question: Having a function change the value a pointer represents in C As an exercise, I am trying to make a generic function that changes a value in an array of undetermined type. I guess it should look like that. void set_value(void * data, void * value, size_t size, int index){ void * position = data + index*size; *position = *value; } Of course that does not compile, *position = *value do not use the information of the size of value (here was assume both data

what is array decay in c and when it happen?

折月煮酒 提交于 2021-02-11 12:19:26
问题 I am currently studying C language. I wonder what 'array decaying' means, and when it happens. And I wonder if the two variables below are interpreted in the same way. char(*zippo)[2] = NULL; char zippo2[4][2]; zippo = (char(*)[2])malloc(sizeof(char[2]) * 4); 回答1: From the C Standard (6.3.2.1 Lvalues, arrays, and function designators) 3 Except when it is the operand of the sizeof operator or the unary & operator, or is a string literal used to initialize an array, an expression that has type

Get pointer on var obtained via interface

大城市里の小女人 提交于 2021-02-11 12:09:28
问题 In the following code var a int var b interface{} b = a fmt.Printf("%T, %T \n", a, &a) fmt.Printf("%T, %T \n", b, &b) output: int, *int int, *interface {} I would expect the type of &b to be a pointer on int. I have two questions: 1) Why is it a pointer on interface{} ? 2) How could I get a pointer on the original type ? 回答1: &b => this is the address operator applied on the variable b , whose type is interface{} . So &b will be a pointer of type *interface{} , pointing to the variable b . If

why is int ** x not the same as int x[][]?

天大地大妈咪最大 提交于 2021-02-11 09:39:07
问题 This may be a dumb question but I don't understand why do I get this error : void func (int ** array) { } int main (void) { int array[5][5] = { }; func(array); } warning: passing argument 1 of 'func' from incompatible pointer type [-Wincompatible-pointer-types] func(array); ^~~~~ note: expected 'int **' but argument is of type 'int (*)[5]' void func (int ** array) { } ~~~~~~~^~~~~ 回答1: Consider a function void foo(int **p) . The p it is given contains some address. At that address, there is

Double pointer as an array to a function [duplicate]

烈酒焚心 提交于 2021-02-11 07:54:29
问题 This question already has answers here : Why can't we use double pointer to represent two dimensional arrays? (5 answers) usage of double pointers as arguments (4 answers) Closed 6 years ago . This is a sample code of my program. I have a function named function which is used to return an integer value and an integer array. I have to pass them as pointers (The signature of function cannot be changed). So I wrote the below code. Here I have to assign the values to the double pointer passed to

Controlling multiple pointers with Xlib or xinput in ubuntu/linux

廉价感情. 提交于 2021-02-10 23:25:50
问题 I'm creating a system that uses multiple cursors (pointers) in multiple xsessions. My computer has multiple video cards in it for controlling different monitors. I want to have a different cursor on each screen and control each. Each monitor is a different session. I started using the xlib library in C to control the single cursor I have using the following command: XWarpPointer(display,None,window,0,0,0,0,x,y); This works perfectly for one cursor. Then I created a second cursor using xinput

Does using locals as arguments in pthread_create() work?

自古美人都是妖i 提交于 2021-02-10 20:14:05
问题 This is mainly a question about scope and threads. Let's say we have the following struct. struct Test { int number; std::string name; }; An instance of this struct will be used as an argument in the pthread_create function. Here is an example of what this might look like. pthread_t tid[5]; for(int i = 0; i < 5; ++i) { Test test; test.number = 5; test.name = "test"; pthread_create(&tid[i], NULL, func, (void *)&test); } Is this acceptable? Since test is declared in the for's scope, that means