• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: #define works, const short does not for Ctype array in class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: #define works, const short does not for Ctype array in class


  • Subject: Re: #define works, const short does not for Ctype array in class
  • From: Robert Kuilman <email@hidden>
  • Date: Mon, 14 Jun 2004 17:37:27 +0200

I got the same problem when trying do declare constant integers, of variables of any other type.
I just #def-ed them. It does the trick, and there should not be a performance loss in it for you..

in that respect, const short is nearly the same as a #define, i think GCC will subtitute both cases for the value
at compile time anyhow.

Robert K.

-----------------------------{ Official Cocoa Newbie! }-----------------------------
web: http://halfduplex.net/
email: email@hidden

On Jun 14, 2004, at 4:23 PM, George Woodrow III wrote:

I have the following code:

const short MaxNEvalValues = 6; // array size for evalValues[]
//#define MaxNEvalValues 6

@interface STQualityStandards : NSObject
{
double tePct; // >= 0.0
double teAbs; // >= 0.0
double sigmaMult; // >= 1.65, default 2.4

short nEvalValues; // 1-6
float evalVals[MaxNEvalValues]; // evalVals[0] must have a value
double maxBiasFac; // default 1, range [0.5, 1.0]
double worstGradeWeight; // [0.0, 1.0], default = 0.3
BOOL useSpecificPatBiasLimitsQ; // normally NO
double patMedLimitPct; // < tePct
double patMedLimitAbs; // < teAbs
}

If I compile this, I get an error:

error: variable-size type declared outside of any function.

If I use the #define, everything works fine, as does hard coding the 6 in the array.

For performance reasons, I need to use a c style array, not an MSMutableArray.

Using the const works in c/c++.

What do I have to do to make it work in Cocoa?

Thanks

George V. Woodrow III
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.



Robert K.

web: http://halfduplex.net/
email: email@hidden
------------------------------------------------------------------------ ---------------------
"Robert's Law: Whenever you have the time to write code, you lack the inspiration. The moment's you are too busy to code, you come up with idea's constantly."
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >#define works, const short does not for Ctype array in class (From: George Woodrow III <email@hidden>)

  • Prev by Date: Panther is flipping my text
  • Next by Date: Protocol and other UML patterns
  • Previous by thread: #define works, const short does not for Ctype array in class
  • Next by thread: Re: #define works, const short does not for Ctype array in class
  • Index(es):
    • Date
    • Thread