LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 01-02-2009, 04:13 PM   #1
DanielKs
LQ Newbie
 
Registered: Dec 2008
Posts: 5

Rep: Reputation: 0
visible on different files?


Ok guys, so I have 2 files, one named "main2.c" and the other named "something.c", very simple ones.

Here is main2.c:
#include <stdio.h>

typedef struct
{
int i;
int j;
}MINE;

void something (MINE var);

int main()
{
MINE p = {10, 20};
something(p);
return 0;
}


Here is "something.c":

#include <stdio.h>

void something (MINE var)
{

printf("value: %d\n", var.j);
}




When I type: gcc main2.c something.c -o main2
./main2

I get this: something.c:5: error: expected ')' before 'var'

WHY ON EARTH DOESN'T THIS WORK!?

The structure is declared outside of any function, so it goes to data segment, right? It is available inside the function something() too, tough its in another file! Right? But when I put the funcion void something (MINE var) on "main2.c" and compile it without "something.c" it works just fine, printing the value 20!

Last edited by DanielKs; 01-02-2009 at 04:15 PM.
 
Old 01-02-2009, 04:37 PM   #2
jiobo
Member
 
Registered: Nov 2008
Posts: 180

Rep: Reputation: 36
The data structure is defined in one file called main, but is not defined in the other file. Look up "extern" or find a good book on building c projects.
 
  


Reply

Tags
different, file, structure


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
files not visible in ftp site (but present in the /var/ftp/folder of the server) dongrila Linux - Newbie 2 12-23-2007 10:09 PM
files not visible on cd nwtlnxqstns Linux - General 10 11-07-2007 04:32 AM
How to use samba implementing some files can visible and some files can not visible willie118 Linux - Server 7 09-18-2007 12:27 AM
Samba: Only first letter of shared files visible betonarbejder Linux - Networking 0 09-25-2006 03:18 PM
Making files visible under wuftp Florian Linux - Software 5 09-25-2002 03:49 PM


All times are GMT -5. The time now is 07:44 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration