Ask a Question related to UNIX Programming, Design and Development.
-
Shinu George #1
Global variable conflict.
I have two files like given below:
/* File 1 */
#include <stdio.h>
#include <stdlib.h>
void tf(void);
int i;
int main(void)
{
i = 10;
tf();
return EXIT_SUCCESS;
}
/* End File 1 */
/* File 2 */
#include <stdio.h>
int i = 48;
void tf(void)
{
printf("%d\n", i);
}
/* End File 2 */
The observed behaviour is that the "printf" always prints the value of i as 10.
Two questions:
1 (for clc). Is the above code standards (ANSI) compliant?
2 (for cup). How do I get the linker to "see" the i with value 48 on Solaris?
Thanks and regards,
Shinu
Shinu George Guest
-
Mod_perl conflict with PHP on HTTP_REFERER variable
Hi. I'm using Apache 1.3.33 / PHP 5.0.4 / Perl 5.8.7 / Mod_perl 1.29 on linux box. And one of virtualhost using Perl::Run and the others using... -
global variable
I have made a site where I need to be able to include a file containing an array of settings in many pages. This array needs to have global scope... -
Global Variable declaration
For some reason this wont compile, it says that i need to declare the variable before using it on prepareMovie global sm204 -
Help Please: 'Warning 5001 global variable "iF_timer" already defined in global scope
Hi there, I have just started to get this error: 'Warning 5001 global variable "iF_timer" already defined in global scope The variable name... -
mod_perl and the global variable?
I have used mod_perl a little bit, I read the CGI porters guide, and it lead me to believe as long as I "use strict" in all my scripts, (declare... -
Emmanuel Delahaye #2
Re: Global variable conflict.
In 'comp.lang.c', [email]supercool_libran@yahoo.co.uk[/email] (Shinu George) wrote:
You can't have two global scope variables with the same name in the same> I have two files like given below:
>
> /* File 1 */
> #include <stdio.h>
> #include <stdlib.h>
>
> void tf(void);
>
> int i;
>
> int main(void)
> {
> i = 10;
> tf();
>
> return EXIT_SUCCESS;
> }
>
> /* End File 1 */
>
> /* File 2 */
> #include <stdio.h>
>
> int i = 48;
project. Your linker should warn you about that.
Won't link at home.> void tf(void)
> {
> printf("%d\n", i);
> }
>
>
> /* End File 2 */
>
>
> The observed behaviour is that the "printf" always prints the value of i
> as 10.
No.> Two questions:
>
> 1 (for clc). Is the above code standards (ANSI) compliant?
If you insist to have these global scope variables, you must reduce their
scope to the file with 'static'.
--
-ed- [email]emdelYOURBRA@noos.fr[/email] [remove YOURBRA before answering me]
The C-language FAQ: [url]http://www.eskimo.com/~scs/C-faq/top.html[/url]
<blank line>
FAQ de f.c.l.c : [url]http://www.isty-info.uvsq.fr/~rumeau/fclc/[/url]
Emmanuel Delahaye Guest
-
E. Robert Tisdale #3
Re: Global variable conflict.
Shinu George wrote:
[snip]
#ifndef GUARD_FILE2_H> cat file2.h
#define GUARD_FILE2_H 1
#include <stdio.h>
#include "file2.h"
extern int i;
void tf(void);
#endif//GUARD_FILE2_H
/* File 2 */> cat file2.c
#include "file2.h"
int i = 48;
void tf(void) {
printf("%d\n", i);
}
/* End File 2 */
/* File 1 */> cat file1.c
#include "file2.h"
#include <stdlib.h>
int main(int argc, char* argv[]) {
tf();
i = 10;
tf();
return EXIT_SUCCESS;
}
/* End File 1 */
48> gcc -Wall -std=c99 -pedantic -O2 -o file file1.c file2.c
> ./file
10
E. Robert Tisdale Guest



Reply With Quote

