Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Grofit

#defines and a small problem..

This topic is 5400 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello... i will try and keep this short and sweet... ive got a define: #define Chunk_Size 128 and i need to get the square root of that number... so i tried #define Row_Size sqrt(Chunk_Size) but that doesnt work.. im guessing because im using a function there.. so is there any way round this... i need to work out the sqrt in a define so i can use it in a 2d array in my classes public area: public: int Array[Row_Size][Row_Size]; am i doing it completly wrong or is there another way round this, i just need it so i can define a number and have this array within public be equal to the rows size.. which is the square root of chunk size..as you can see above.. Thanks to anyone who can help...

Share this post


Link to post
Share on other sites
Advertisement
Why not use constants......

const int Chunk_Size = 128;

int squared_size = sqrt(Chunk_Size);

[edited by - SumDude on February 28, 2004 9:53:15 PM]

Share this post


Link to post
Share on other sites
Your problem is probably that sqrt returns a double. Its very difficult to have an array with 11.313708498985X11.313708498985 dimensions. Make it a square. If it still doesn''t work try:

#define Row_Size (int)sqrt(Chunk_Size)

or better yet (squaring is MUCH faster than square-rooting,

#define Row_Size 8
#define Chunk_Size Row_Size*Row_Size

Zorx (a Puzzle Bobble clone)
Discontinuity (an animation system for POV-Ray)

Share this post


Link to post
Share on other sites
sorry i thought i had put in the (int) bit.. lol it would be funny if you could have an array of [0.3334343]... but yeah anyway i went with the row*row method... i just wanted to specify an overall size.... thanks for your help anyway ...

Share this post


Link to post
Share on other sites
quote:
Original post by SumDude
Why not use constants......



Could be useful in interfacing with C code. In C, "const" is more like "read only". It''s not actually a constant expression. I think the following produces a VLA in C99 (and is illegal in C89)

const size_t n = 10;
int array[n][n] = {0};

But I could be wrong. Also, I think clum''s

#define Row_Size (int)sqrt(Chunk_Size)

will fail for a similar reason in both C++ and C89 (producing a VLA in C99)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!