Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

187
Vistas
Can a static variable be declared extern in C?

So, let's say, I have:

file1.c

int i;
static int j;
int main ()
{
    for ( int k = 0; k < 10; k++ )
    {
       int foo = k;
    }
}

file2.c

{
// the following statements are before main.
extern int i; // this is acceptable, I know since i acts as a global variable in the other file
extern int j; // Will this be valid? 
extern int foo; // Will this be valid as well?
}

I therefore, have a doubt that the statements marked with a question mark, will they be valid?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

No! static globals have file scope (internal linkage), so you can't use them as they have external linkage... This does not means that you cannot have a variable of the same name with external linkage but it cannot be that one that is static.

Correct for i.

Incorrect for j, at least it cannot be the one defined in file1.c.

Incorrect for foo, at least for the local variable used in file2.c which does not have external linkage (no linkage at all). A local variable only exists when the block where it is declared is activated, so having access to it outside is a non-sense.

over 4 years ago · Santiago Trujillo Denunciar

0

extern int j; is not a valid -> static variables are with in the file scope

extern int foo; is not valid -> foo is a local variable whose scope is with in the 'for' loop

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda