Search Results

Search found 3887 results on 156 pages for 'pointer arithmetic'.

Page 27/156 | < Previous Page | 23 24 25 26 27 28 29 30 31 32 33 34  | Next Page >

  • Read from file into pointer to struct

    - by cla barzu
    I need help with pointers in C. I have to read from a file, and fill an array with pointers to struct rcftp_msg . Since now I did the next things: struct rcftp_msg { uint8_t version; uint8_t flags; uint16_t len; uint8_t buffer[512]; }; struct rcftp_msg *windows [10]; pfile = fopen(file,"r"); // Open the file I have to read from the file into the buffer, but I don't know how to do it. I tried the next: for (i = 0; i <10; i++){ leng=fread (**windows[i]->buffer**,sizeof(uint8_t),512,pfile); } I think windows[i]-buffer is bad, cuz that don't work. Sorry for my bad English :(

    Read the article

  • Null pointer exception on .iterator() call

    - by Peter
    I'm getting a strange NullPointerException, evidently thrown by the following line of code: Iterator<Note> it = notes.iterator(); I've checked, and at the time the java.util.TreeSet notes is always non-null (with 15 elements). The TreeSet API says nothing about iterator() throwing NullPointerExceptions. What else could be going here?

    Read the article

  • Passing a pointer to an array to glGenBuffers

    - by Josh Elsasser
    I'm currently passing an array to a function, then attempting to use glGenBuffers with the array that is passed to the function. I can't figure out a way to get glGenBuffers to work with the array that I've passed. I have a decent grasp of the basics of pointers, but this is beyond me. This is basically how the render code works. It's a bit more complex, (colours using the same array idea, also not working) but the basic idea is as follows: void drawFoo(const GLfloat *renderArray, GLuint verticeBuffer) { glBindBuffer(GL_ARRAY_BUFFER, verticeBuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(verticeBuffer)*sizeof(GLfloat), verticeBuffer, GL_STATIC_DRAW); glVertexPointer(2, GL_FLOAT, 0, 0); glEnableClientState(GL_VERTEX_BUFFER); glDrawArrays(GL_TRIANGLE_FAN, 0, 45); glDisableClientState(GL_VERTEX_BUFFEr); } Thanks in advance for the help

    Read the article

  • Duplicate array but maintain pointer links

    - by St. John Johnson
    Suppose I have an array of nodes (objects). I need to create a duplicate of this array that I can modify without affecting the source array. But changing the nodes will affect the source nodes. Basically maintaining pointers to the objects instead of duplicating their values. // node(x, y) $array[0] = new node(15, 10); $array[1] = new node(30, -10); $array[2] = new node(-2, 49); // Some sort of copy system $array2 = $array; // Just to show modification to the array doesn't affect the source array array_pop($array2); if (count($array) == count($array2)) echo "Fail"; // Changing the node value should affect the source array $array2[0]->x = 30; if ($array2[0]->x == $array[0]->x) echo "Goal"; What would be the best way to do this?

    Read the article

  • Indexing with pointer C/C++

    - by Leavenotrace
    Hey I'm trying to write a program to carry out newtons method and find the roots of the equation exp(-x)-(x^2)+3. It works in so far as finding the root, but I also want it to print out the root after each iteration but I can't get it to work, Could anyone point out my mistake I think its something to do with my indexing? Thanks a million :) #include <stdio.h> #include <math.h> #include <malloc.h> //Define Functions: double evalf(double x) { double answer=exp(-x)-(x*x)+3; return(answer); } double evalfprime(double x) { double answer=-exp(-x)-2*x; return(answer); } double *newton(double initialrt,double accuracy,double *data) { double root[102]; data=root; int maxit = 0; root[0] = initialrt; for (int i=1;i<102;i++) { *(data+i)=*(data+i-1)-evalf(*(data+i-1))/evalfprime(*(data+i-1)); if(fabs(*(data+i)-*(data+i-1))<accuracy) { maxit=i; break; } maxit=i; } if((maxit+1==102)&&(fabs(*(data+maxit)-*(data+maxit-1))>accuracy)) { printf("\nMax iteration reached, method terminated"); } else { printf("\nMethod successful"); printf("\nNumber of iterations: %d\nRoot Estimate: %lf\n",maxit+1,*(data+maxit)); } return(data); } int main() { double root,accuracy; double *data=(double*)malloc(sizeof(double)*102); printf("NEWTONS METHOD PROGRAMME:\nEquation: f(x)=exp(-x)-x^2+3=0\nMax No iterations=100\n\nEnter initial root estimate\n>> "); scanf("%lf",&root); _flushall(); printf("\nEnter accuracy required:\n>>"); scanf("%lf",&accuracy); *data= *newton(root,accuracy,data); printf("Iteration Root Error\n "); printf("%d %lf \n", 0,*(data)); for(int i=1;i<102;i++) { printf("%d %5.5lf %5.5lf\n", i,*(data+i),*(data+i)-*(data+i-1)); if(*(data+i*sizeof(double))-*(data+i*sizeof(double)-1)==0) { break; } } getchar(); getchar(); free(data); return(0); }

    Read the article

  • When convert a void pointer to a specific type pointer, which casting symbol is better, static_cast or reinterpret_cast?

    - by BugCreater
    A beginner question with poor English: Here I got a void* param and want to cast(or change) it to a specific type. But I don't know which "casting symbol" to use. Either**static_cast** and reinterpret_cast works. I want to know which one is better? which one does the Standard C++ recommend? typedef struct { int a; }A, *PA; int foo(void* a) // the real type of a is A* { A* pA = static_cast<A*>(a); // or A* pA = reinterpret_cast<A*>(a);? cout<<pA->a<<endl; return 0; } Here I use A* pA = static_cast(a); or A* pA = reinterpret_cast(a); is more proper?

    Read the article

  • Pointer mysteriously moves

    - by Armen Ablak
    Hi, I have this code for Node rotation and in a line which is marked something happens and I don't really know what and why :). //Test case 30 \ 16 / 29 RotationRight(node->mParent); //call template<class T> void SplayTree<T>::RotationRight(SplayNode<T> *&node) const { SplayNode<T> *left = node->mLeft; SplayNode<T> *parent = node->mParent; node->mLeft = left->mRight; if(left->HasRight()) left->mRight->mParent = node; left->mRight = node; //node in this line points to 0x00445198 {30} left->mParent = node->mParent; //and in this line it points to 0x00444fb8 {16} (node, not node->mParent) node->mParent = left; node = left; } Well, left-mParent points to node also, so I basically do node = node-mParent. The problem is I can't find a work around - how to unpin in from node and change it's pointing address without changing it's.

    Read the article

  • Disallow taking pointer/reference to const to a temporary object in C++ (no C++0X)

    - by KRao
    Hi, I am faced with the following issue. Consider the following class: //Will be similar to bost::reference_wrapper template<class T> class Ref { public: explicit Ref(T& t) : m_ptr(&t) {} private: T* m_ptr; }; and this function returning a double double fun() {return 1.0;} If we now have double x = 1.0; const double xc = 1.0; Ref<double> ref1(x); //OK Ref<const double> refc1(cx); //OK good so far, however: //Ref<double> ref2( fun() ); //Fails as I want it to Ref<const double> refc2( fun() ); //Works but I would like it not to Is there a way to modify Ref (the way you prefer) but not the function fun, so that the last line returns a compile-time error? Please notice you can modify the constructor signature (as long as I am able to initialise the Ref as intended). Thank you in advance for your help!

    Read the article

  • Doubt on pointer conversion

    - by Simone
    Suppose we have the following code: #include <iostream> struct A { virtual void f() { std::cout << "A::f()" << std::endl; } }; struct B: A { void f() { std::cout << "B::f()" << std::endl; } }; void to_A(void* voidp) { A* aptr = static_cast<A*>(voidp); aptr->f(); } void to_B(void* voidp) { B* bptr2 = static_cast<B*>(voidp); bptr2->f(); } int main() { B* bptr = new B; void* voidp = bptr; to_A(voidp); // prints B::f() to_B(voidp); // prints B::f() } is this code guaranteed to always work as in the code comments or is it UB? AFAIK it should be ok, but I'd like to be reassured.

    Read the article

  • Dereferencing possible null pointer in java

    - by Nealio
    I am just starting to get into graphics and when I am trying to get the graphics, I get the error"Exception in thread "Thread-2" java.lang.NullPointerException" and I have no clue on what is going on! Any help is greatly appreciated. //The display class for the game //Crated: 10-30-2013 //Last Modified: 10-30-2013 package gamedev; import gamedev.Graphics.Render; import gamedev.Graphics.Screen; import java.awt.Canvas; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Toolkit; import java.awt.image.BufferStrategy; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; import javax.swing.JFrame; private void tick() { } private void render() { System.out.println("display.render"); BufferStrategy bs = this.getBufferStrategy(); if (bs == null) { createBufferStrategy(3); } for (int i = 0; i < GAMEWIDTH * GAMEHEIGHT; i++) { pixels[i] = screen.PIXELS[i]; } screen.Render(); //The line of code that is the problem Graphics g = bs.getDrawGraphics(); //end problematic code g.drawImage(img, 0, 0, GAMEWIDTH, GAMEHEIGHT, null); g.dispose(); bs.show(); }

    Read the article

  • Would a pointer to a pointer to nil match against NULL?

    - by dontWatchMyProfile
    Example: A validation method contains this check to see if an NSError object shall be created or not: - (BOOL)validateCompanyName:(NSString *)newName error:(NSError **)outError { if (outError != NULL) { // do it... Now I pass an NSError object, like this: NSError *error = nil; BOOL ok = [self validateCompanyName:@"Apple" error:&error]; I'm not sure if this matches the check for not NULL. I think it's not NULL, since I believe NULL is not nil. Maybe someone can clear this up?

    Read the article

  • Delegates with explicit "this" pointer?

    - by Qwertie
    Is it possible to adapt a method like this function "F" class C { public void F(int i); } to a delegate like Action<C,int>? I have this vague recollection that Microsoft was working on supporting this kind of adaptation. But maybe I misremembered!

    Read the article

  • how to make struct member pointer in assembly?

    - by sillis
    I`m trying to create a macro which would make easier to point to a structs member. Currently i am pointing to a structs member in assembly file using the STRUCT_NAME + offset method. For example if i want to point structs third member,i would have to do it like this: STRUCT_NAME + 3. This seems stupid way to do it, and if i insert more members in the struct, i have to update all the offset values in the code. Is there a way to point using STRUCT_NAME + macro(struct_name, member_name) ? I`m using texas instruments TMS320C28x hardware. Thanks!

    Read the article

  • What does this pointer-heavy C code do?

    - by justRadojko
    Could someone explain to me what should two following lines do: s.httpheaderline[s.httpheaderlineptr] = *(char *)uip_appdata; ++((char *)uip_appdata); This is taken from uIP code for microcontrollers. s - structure httpheaderline - http packet presented as a string httpheadrlineptr - integer value uip_appdata - received ethernet packet (string) If some more info is needed please let me know. BTW. Eclipse is reporting an error on the second line with message Invalid lvalue in increment so i'm trying to figure out how to solve this.

    Read the article

  • Void pointer cast C++ and GTK

    - by Tarantula
    See this GTK callback function: static gboolean callback(GtkWidget *widget, GdkEventButton *event, gpointer *data) { AnyClass *obj = (AnyClass*) data; // using obj works } (please note the gpointer* on the data). And then the signal is connected using: AnyClass *obj2 = new AnyClass(); gtk_signal_connect(/*GTK params (...)*/, callback, obj2); See that the *AnyClass is going to be cast to gpointer* (void**). In fact, this is working now. The callback prototype in GTK documentation is "gpointer data" and not "gpointer *data" as shown in code, what I want to know is: how this can work ? Is this safe ?

    Read the article

  • Cast A primitive type pointer to A structure pointer - Alignment and Padding?

    - by Seçkin Savasçi
    Just 20 minutes age when I answered a question, I come up with an interesting scenario that I'm not sure of the behavior: Let me have an integer array of size n, pointed by intPtr; int* intPtr; and let me also have a struct like this: typedef struct { int val1; int val2; //and less or more integer declarations goes on like this(not any other type) }intStruct; My question is if I do a cast intStruct* structPtr = (intStruct*) intPtr; Am I sure to get every element correctly if I traverse the elements of the struct? Is there any possibility of miss-alignment(possible because of padding) in any architecture/compiler?

    Read the article

  • javascript function pointer and "this"

    - by Justin808
    I'm passing a method as a variable to be used as a callback. When its called, the "this" is not the object the method is a member of. How do I go about getting access to the method's object instance so I can get access to it variables and other member functions? I have no control over the callback call method, its a separate library. All I do is call the binding from my object init method. I would have expected this inside my _connection method to have been its object. jsPlumb.bind('connection', this._connection);

    Read the article

  • Misaligned Pointer Performance

    - by Elite Mx
    Aren't misaligned pointers (in the BEST possible case) supposed to slow down performance and in the worst case crash your program (assuming the compiler was nice enough to compile your invalid c program). Well, the following code doesn't seem to have any performance differences between the aligned and misaligned versions. Why is that? /* brutality.c */ #ifdef BRUTALITY xs = (unsigned long *) ((unsigned char *) xs + 1); #endif ... /* main.c */ #include <stdio.h> #include <stdlib.h> #define size_t_max ((size_t)-1) #define max_count(var) (size_t_max / (sizeof var)) int main(int argc, char *argv[]) { unsigned long sum, *xs, *itr, *xs_end; size_t element_count = max_count(*xs) >> 4; xs = malloc(element_count * (sizeof *xs)); if(!xs) exit(1); xs_end = xs + element_count - 1; sum = 0; for(itr = xs; itr < xs_end; itr++) *itr = 0; #include "brutality.c" itr = xs; while(itr < xs_end) sum += *itr++; printf("%lu\n", sum); /* we could free the malloc-ed memory here */ /* but we are almost done */ exit(0); } Compiled and tested on two separate machines using gcc -pedantic -Wall -O0 -std=c99 main.c for i in {0..9}; do time ./a.out; done

    Read the article

  • question regarding "this" pointer in c++

    - by sil3nt
    hello there, i have been given class with int variables x and y in private, and an operator overload function, class Bag{ private: int x; int y; public: Bag(); ~Bag(); //....... //.....etc }; Bag operator+ (Bag new) const{ Bag result(*this); //what does this mean? result.x += new.x; result.y += new.y; } What is the effect of having "Bag result(*this);" there?.

    Read the article

  • C/C++ opaque pointer library

    - by aaa
    hello Is there library/header already written to manage C++ objects from C using opaque pointers/handles? I can write one myself, but I would rather use already made solution, especially if it has fortran bindings. Thanks

    Read the article

  • Why do I get a Null Pointer Exception?

    - by Roman
    I have this code: Manager manager = new Manager("Name"); MyWindowListener windowListener = new MyWindowListener(); manager.addWindowListener(windowListener); Eclipse writes that I have a NullPointerException in the last line. What can be the reason for that. I do have constructors in the Manager and MyWindowListener. If it's important MyWindowListener implements WindowListener.

    Read the article

  • Doubt regarding usage of array as a pointer in C

    - by Som
    For eg. I have an array of structs 'a' as below: struct mystruct{ int b int num; }; struct bigger_struct { struct my_struct a[10]; } struct bigger_struct *some_var; i know that the name of an array when used as a value implicitly refers to the address of the first element of the array.(Which is how the array subscript operator works at-least) Can i know do the other way around i.e if i do: some_var->a->b, it should be equivalent to some_var->a[0]->b, am i right? I have tested this and it seems to work , but is this semantically 100% correct?

    Read the article

  • Obtaining frame pointer in C

    - by assketchum
    I'm trying to get the FP in my C program, I tried two different ways, but they both differ from what I get when I run GDB. The first way I tried, I made a protocol function in C for the Assembly function: int* getEbp(); and my code looks like this: int* ebp = getEbp(); printf("ebp: %08x\n", ebp); // value i get here is 0xbfe2db58 while( esp <= ebp ) esp -= 4; printf( "ebp: %08x, esp" ); //value i get here is 0xbfe2daec My assembly code getEbp: movl %ebp, %eax ret I tried making the prototype function to just return an int, but that also doesn't match up with my GDB output. We are using x86 assembly. EDIT: typos, and my getEsp function looks exactly like the other one: getEsp: movl %esp, %eax ret

    Read the article

  • Extract inputs from a pointer to array of characters in C / C++

    - by user2066884
    I am writing a command line utility but I cannot find a way to store the commands and arguments. so far I have the following but I get a Segmentation fault: int main(void) { char *command; char *args[MAX_LINE/2 + 1]; int should_run = 1; do{ cout << "cmd> "; int counter = 0; while(cin >> command) { strcpy(args[counter],command); counter++; } cout << args[0] << "\n"; } }

    Read the article

  • Changing Value of Array Pointer When Passed to a Function

    - by ZAX
    I have a function which receives both the array, and a specific instance of the array. I try to change the specific instance of the array by accessing one of its members "color", but it does not actually change it, as can be seen by debugging (checking the value of color after function runs in the main program). I am hoping someone can help me to access this member and change it. Essentially I need the instance of the array I'm specifying to be passed by reference if nothing else, but I'm hoping there is an easier way to accomplish what I'm trying to do. Here's the structures: typedef struct adjEdge{ int vertex; struct adjEdge *next; } adjEdge; typedef struct vertex{ int sink; int source; int color; //0 will be white, 1 will be grey, 5 will be black int number; adjEdge *nextVertex; } vertex; And here is the function: void walk(vertex *vertexArray, vertex v, int source, maxPairing *head) { int i; adjEdge *traverse; int moveVertex; int sink; traverse = vertexArray[v.number-1].nextVertex; if(v.color != 5 && v.sink == 5) { sink = v.number; v.color = 5; addMaxPair(head, source, sink); } else { walk(vertexArray, vertexArray[traverse->vertex-1], source, head); } } In particular, v.color needs to be changed to a 5, that way later after recursion the if condition blocks it.

    Read the article

< Previous Page | 23 24 25 26 27 28 29 30 31 32 33 34  | Next Page >