Page 1 of 1

min/max on Linux

Posted: Tue Sep 25, 2012 8:07 pm
by John Adams
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?

Re: min/max on Linux

Posted: Tue Sep 25, 2012 8:14 pm
by Zcoretri
What is linux again? :mrgreen:

Re: min/max on Linux

Posted: Tue Sep 25, 2012 8:14 pm
by Jabantiz
I thought I was using this wich is <algorithm> not "WinDef.h" and it is std so thought it was ok on linux.

Re: min/max on Linux

Posted: Wed Sep 26, 2012 4:56 pm
by John Adams
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.