How to pass handle from SD.open() to a function?

Hello,
My code has something like this:

...
File handle;
handle=SD.open("some.txt");
dostuff(handle);
}

void dostuff(File han)
{
han.close();
}
...

I am having trouble setting the parameters right. I tried having:

...
File handle;
handle=SD.open("some.txt");
dostuff(&handle);
}

void dostuff(File *han)
{
(&han).close();
}
...

etc. but I get compile errors from IDE at compile time. I am used to using plain C function and structures.

void dostuff(File &hand);

void setup()
{
   File myFile = SD.open("some.txt");
   dostuff(myFile);
}

Knowing what the function signature needs to be will make writing the function trivial.

My code has something like this:

Why can't we see what it actually looks like, in code tags?

This does not produce error at compile:

void setup()
{
   File myFile = SD.open("some.txt");
   dostuff(myFile);
}

void dostuff(File &han)
{
han.close();
}

void loop()
{
}

How would I pass a NULL on dostuff() and test if han is NULL?

There is no such thing as a null reference.

File has operator bool so you

newuser:
This does not produce error at compile:

void setup()

{
  File myFile = SD.open("some.txt");
  dostuff(myFile);
}

void dostuff(File &han)
{
han.close();
}

void loop()
{
}




How would I pass a NULL on dostuff() and test if han is NULL?

the File class has operator bool so you can test "if (myFile)"