min/max on Linux

Support forum for questions about compiling and running EQ2Emulator on Linux.

Moderator: Team Members

Post Reply
User avatar
John Adams
Retired
Posts: 9684
Joined: Thu Jul 26, 2007 6:27 am
EQ2Emu Server: EQ2Emulator Test Center
Characters: John
Location: Arizona
Contact:

min/max on Linux

Post by John Adams » Tue Sep 25, 2012 8:07 pm

I realize you guys love Windows :mrgreen:

But some of us are still Linux fans. Please be sure when finding fancy features to use in C++ that they are cross-platform with Linux too.

Code: Select all

packet->setArrayDataByName("build_selected_item_qty", min(item->details.count, recipe->GetBuild1ComponentQuantity()), index);
I am looking, but cannot find the NIX equivalent for WinDef.h yet. Any hints?

User avatar
Zcoretri
Team Member
Posts: 1642
Joined: Fri Jul 27, 2007 12:55 pm
Location: SoCal

Re: min/max on Linux

Post by Zcoretri » Tue Sep 25, 2012 8:14 pm

What is linux again? :mrgreen:

Jabantiz
Lead Developer
Posts: 2912
Joined: Wed Jul 25, 2007 2:52 pm
Location: California

Re: min/max on Linux

Post by Jabantiz » Tue Sep 25, 2012 8:14 pm

I thought I was using this wich is <algorithm> not "WinDef.h" and it is std so thought it was ok on linux.

User avatar
John Adams
Retired
Posts: 9684
Joined: Thu Jul 26, 2007 6:27 am
EQ2Emu Server: EQ2Emulator Test Center
Characters: John
Location: Arizona
Contact:

Re: min/max on Linux

Post by John Adams » Wed Sep 26, 2012 4:56 pm

Jab, this is from Scatman (who is out of town this week). Hopefully it clears up the mystery for you, because it's still Chinese to me :)
min/max are C++ functions. notice they use template<> instead of actual integer types. since they use templates<>, the compiler figures out the types at compile time and the function definition says they must be the same type.

template <class T> const T& min ( const T& a, const T& b );

notice: const T&a and const T& b.

T is the type (unknown until compile time) but they must be the same since they are both T. well an int16 and an int8 were being passed in so it complained. i casted the int16's to int8's since they were being used in a packet struct with an int8 type. so it'll compare two int8's and return an int8.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests