Jump to content
  • Advertisement
Sign in to follow this  
mashrub

function(arg1 arg2)

This topic is 4571 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

Hi, well I feel a bit stupid asking this because it seems very basical programming but I had never seen until today.
function(arg1 | arg2)
Does the "|" have something to do with the bitwise operator? What does it exactly mean here? Thank you for your help!

Share this post


Link to post
Share on other sites
Advertisement
Which language?

assuming C/C++, it means exactly what you'd expect. First, bitwise OR arg1 and arg2 together, then call the function with the result.

Share this post


Link to post
Share on other sites
(arg1 | arg2) is an expression in C or C++. It gets evaluated first and its result is passed to the function. So in this case the function has one parameter.

Both arg1 and arg2 are probably int's. This is all part of the world of bitflags/bitfields. Each bit specifies a boolean value for some option, which saves space when you have a bunch of options to toggle on/off.

Here is an example

IMG_SCALE_POW2 00000000000000000000000000000001
IMG_FILTER_NONE 00000000000000000000000000000010


The bit on the far left specifies if you want to scale the image. The next bit over specifies no filtering to be used. Now you want both of these options and the function takes a single integer whose bits are the options.


IMG_SCALE_POW2 | IMG_FILTER_NONE
00000000000000000000000000000011


The bitwise OR operator combines the two options in the appropriate manner so the integer we pass to the function has both options set.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!