static int versus static without int in Arduino versus AS7

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

When I use Arduino IDE 1.8.11, static need to add int. When I use AS7, static does not require int.  What are the cause of this different and how can I make the two programming environment the same    ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What do you mean "does not require" ?

 

"static" is completely optional. It's simply about limiting name scope to reduce external visibility of symbols.

 

If you are talking about name clashes (two globals with the same name in different compilation units like 'counter' or something) then static will limit each symbol to it's local compilation unit but in C++ a better solution is possibly the use of namspaces.

 

Or is this because by "AS7" you mean you have switched to C from the C++ that Arduino uses? If that is the case and you want the "Arduino experience" in AS7 then create C++ not C projects (ie make sure source files have .cpp not .c extensions).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hamisu wrote:
When I use Arduino IDE 1.8.11, static need to add int. When I use AS7, static does not require int.

Why no example ?

You might know exactly what you mean; but we don't.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What programming language are you talking about? C? C++?

In C declarations without an explicit type specifier used to be legal in "classic" standard C - C89/90. This is known as "implicit int rule". Starting from C99 this is no longer allowed. In modern standard C a type specifier must be present in a declaration. If you want `int`, you have to say it explicitly.

In C++ such "implicit int rule" never existed in the first place.

Apparently in one case you are dealing with a "loose" C compiler that supports "implicit int" for backward compatibility purposes, and in another case - with a "strict" C (or C++) compiler that properly enforces the current rules of the language.

Dessine-moi un mouton

Last Edited: Thu. Aug 20, 2020 - 10:10 AM