Go Back   EQEmulator Home > EQEmulator Forums > General > General::General Discussion

General::General Discussion General discussion about EverQuest(tm), EQEMu, and related topics.
Do not post support topics here.

Reply
 
Thread Tools Display Modes
  #1  
Old 11-19-2012, 12:49 AM
Uleat's Avatar
Uleat
Developer
 
Join Date: Apr 2012
Location: North Carolina
Posts: 2,815
Default Array Question

I'm working on reducing some redundant code segments and ran across something that I'm curious about.


In my mod, I have 5 elements and initialize my array as <type> myarray[5] = {arg1, arg2, arg3, arg4, arg5}.

I reference it using a zero-based index and everything works just fine.


However, I ran across this snippet and can't figure out why it's coded this way.

Code:
const char *message_arg[9] = {0};

<...>

i = 0;
message_arg[i++] = message1;
message_arg[i++] = message2;
message_arg[i++] = message3;
message_arg[i++] = message4;
message_arg[i++] = message5;
message_arg[i++] = message6;
message_arg[i++] = message7;
message_arg[i++] = message8;
message_arg[i++] = message9;
Does this method assign the first value at index [0] or [1]? (If [1], will adding the string value to message_arg[9] throw an exception, or am I missing something?)

Each message# is passed as a parameter into the function.


Thanks!
__________________
Uleat of Bertoxxulous

Compilin' Dirty
Reply With Quote
  #2  
Old 11-19-2012, 01:05 AM
lerxst2112
Demi-God
 
Join Date: Aug 2010
Posts: 1,742
Default

i++ is known as a post-increment. That means it saves the initial value, increments it, then returns the initial value. By comparison, ++i simply increments the value and returns it. This is why the pre-increment is preferred when using iterators, since it potentially avoids a copy.

Based on that description you can probably figure out what that code does. Of course, you could also figure out what it does based on the fact that it doesn't corrupt the stack which it would if it was starting at index 1.
Reply With Quote
  #3  
Old 11-19-2012, 01:16 AM
Uleat's Avatar
Uleat
Developer
 
Join Date: Apr 2012
Location: North Carolina
Posts: 2,815
Default

That makes sense! Thanks!

I'm still trying to convert what little I know about VB into VC++, so I miss some basic concepts more often than not...
__________________
Uleat of Bertoxxulous

Compilin' Dirty
Reply With Quote
Reply

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 -4. The time now is 05:49 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3