Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :

Go Back   Cockos Incorporated Forums > Other Software Discussion > WDL users forum

Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 01-13-2024, 04:48 PM   #1
Human being with feelings
Join Date: Apr 2010
Location: Portland OR
Posts: 217
Default C++ question - overlapping arrays?

I need to do something rather unorthodox in C++. Can't find the answer anywhere online.

I need to define an array that overlaps another array, so both arrays read from and write to the same memory locations. Related, I also need to define an array of chars that overlaps an array of strings.

Something like this:
byte originalArray[256];
byte myArray = originalArray + 128; // an array of bytes, it starts halfway in

if (myArray[0] == myArray[1]) {     // read from originalArray[128] and [129]
  myArray[2] = 3;                   // write to originalArray[130]
Do I need to define the length of myArray? If so, how?

2nd example, for strings:
char originalArray [10][32];        // 10 null-terminated strings, length <= 31
char myArray = originalArray + 128; // an array of chars, not null-terminated

if (myArray[0] == ' ') {            // read/write 1st char of 5th string
  myArray[0] = '!';
I know this is not good programming practice. But I absolutely positively have to do it this way! (Long story.)
alt-tuner: a microtonal midi plug-in:
The Kite Guitar, a playable 41-ET guitar:
Kite is offline   Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -7. The time now is 09:26 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.