mercredi 19 août 2020

In C++11, can you declare global variables and function prototypes on the same line?

While I was writing some C++11 code:

#include <bits/stdc++.h>
using namespace std;

int a, b, array[25];
int function();

int main() {
... (not important)

out of curiosity, I put the variable declarations in the same line as the function prototype:

#include <bits/stdc++.h>
using namespace std;

int function(int p), a, b, array[25];

int main() {
... (not important)

It compiled properly on XCode (set to [-std=c++11]) and a, b, array[] could be used like normal variables/arrays.

Will this work across most/all compilers, and is this discouraged/fine? Why does this work in C++ (function prototypes and variable declarations seem quite different...)

Thank you in advance for your time.

Aucun commentaire:

Enregistrer un commentaire