23266

Adding to a Memory Address Error

This doesn't compile in VSC++ 2008.

void* toSendMemory2 = toSendMemory + 4;

I am at a loss at why, though I am sure it's very stupid of me. :P

Answer1:

When you add N to a T* the pointer will be incremented by sizeof(T) * N bytes. sizeof(void) is nonsensical, so pointer arithmetic over void* is not allowed.

Answer2:

You can't do pointer arithmetic on void pointers. Try casting (toSendMemory) to a (char *) first (assuming you want to add 4 bytes to it).

Recommend

  • VSC Icons Broken
  • Golang Build in docker not finding local import
  • Dynamic matrix width to always equal chart width
  • how to insert a new column in a dataset with values if it satisfies a statement
  • How can I retrieve all employees whose age will be 21 in a month's time?
  • CDI: Injecting single instance works, but injecting Instance does not. Why?
  • SIP Makefile fail (gnuwin and mingw)
  • Typecasting `this` of a base class template to its derived class
  • How to initialize context? [closed]
  • How to add learning rate to summaries?
  • Add Windows Feature from C#
  • Thread 1: EXC_BAD_ACCESS (code =1 address = 0x0)
  • Object and struct member access and address offset calculation
  • How to assign byte[] as a pointer in C#
  • Groovy: Unexpected token “:”
  • iOS: Detect app start via notification press
  • how to adjust image in a panel in Java swing?
  • Initializer list vs. initialization method
  • How to access EntityManager inside Entity class in EJB3
  • how to do an event when i swipe from fragment to the other
  • JFileChooser in front of fullscreen Swing application
  • Read text file and split every line in MSBuild
  • HTML download movie download link
  • How to draw moving and Running sine wave chart using JFree chart in java?
  • Possible to stop flickering java tooltip in heavyweight mode?
  • sending/ receiving email in Java
  • Eraser for UIBezierPath
  • Suggestions to manage Login/Logout transitions
  • Angular 2 constructor injection vs direct access
  • Java static initializers and reflection
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • Android Google Maps API OnLocationChanged only called once
  • Qt: Run a script BEFORE make
  • unknown Exception android
  • EntityFramework adding new object to nested object collection
  • Checking variable from a different class in C#
  • How can i traverse a binary tree from right to left in java?
  • failed to connect to specific WiFi in android programmatically
  • UserPrincipal.Current returns apppool on IIS
  • How can I use threading to 'tick' a timer to be accessed by other threads?