Variables in Library

If I create a public variable in my main arduino sketch before my setup() and loop() functions, is there a way to see, use, and change these variables in a library without specifically passing them to the library through a function.

For example could I change the variable in the following code without using a the return command in my library function?

include library.h

library L;

int number = 2;

void setup() {
  Serial.begin(9600);
  L.function()

}

void loop() {
  // put your main code here, to run repeatedly: 
  Serial.println(number);
}

For example could I change the variable in the following code without using a the return command in my library function?

If, in library.h, you have a statement:

extern int number;

Then, number in the library function(s) will refer to the same memory location as number in the sketch.

Don't expect me to be interested in using such a library, though. Libraries should be developed in such a way that they are completely independent of the sketch that is using the library.

Please, re-think this.

Great! Thanks for the quick reply PaulS. Your answer makes a lot of sense so I will follow your advice and find a better way. My problem is that I need to pass several variables back to my main sketch after using a function; however, I now realize I can use an array, or possibly even a class to accomplish this.

however, I now realize I can use an array, or possibly even a class to accomplish this.

Reference variables are another possibility.

The advantage with reference variables is that a user of the library knows what is potentially going to be modified.

The disadvantage, minor, is that it is not possible to tell, looking at a function call, which variables are input only and which are input/output.

Another, also minor, is that the IDE is not good at building prototypes for functions with reference variables, so you need to supply the prototype. If the function using the reference variables is a class method, you need to supply the prototype, anyway, so this is a non-issue.