Viewing Arduino Function Code

I would like to view the actual C code for Arduino functions. Currently I want to view the actual C code for the shiftOut() function. Please tell me how to do this. Thanks.

It's all in your Arduino core directory.

Search for the appropriate C files in your Arduino installation.


Rob

Currently I want to view the actual C code for the shiftOut() function.

Well, you have our permission.

Please tell me how to do this.

Find the file it is defined in, and open that file in a text editor.

How to find the file depends on what operating system you are using. If it's Windows, you are pretty much hosed. Finding data in files, like the string "shiftOut", is only possible in certain kinds of files. Which kinds Microsoft won't tell you, but it is obvious that c files, cpp files, and h files are not among the types that Windows Explorer has a clue about.

The function is actually defined in wiring_shift.c.

Thank you all. I found the shiftOut() code in wiring_shift.c. Now to understand it. Again many thanks.

Followup Question

Can anyone explain the purpose of the !! (double NOT?) in the following line of code from shiftOut()?

digitalWrite(dataPin, !!(val & (1 << i)));

Try this:

void setup(){
  Serial.begin(115200);
  Serial.println((2&(1<<1)));
  Serial.println(!!(2&(1<<1)));
}//setup()

void loop(){}//loop()

nilton61:
Try this:

void setup(){

Serial.begin(115200);
  Serial.println((2&(1<<1)));
  Serial.println(!!(2&(1<<1)));
}//setup()

void loop(){}//loop()

I ran your code and see that you get the required result when println is called, but wouldn’t the term (2&(1<<1)) result in the byte 00000010 directly and wouldn’t that byte be passed to the shift register without the !! ?

Thanks for your help.

Never mind. I think I see now. The byte 00000001 must be passed to the shift register. The 1 bit will then be shifted into its proper binary position when the shiftOut() call returns.

Double not ensures any true value (non-zero) is reduced to a single least-significant bit.

AWOL: Double not ensures any true value (non-zero) is reduced to a single least-significant bit.

Thanks. That's it in a nutshell and I now understand why this is required in terms of shift register operation.