Go to Post the political parties should consist of AndyMarkcrats and IFI-icans.... - Josh Hambright [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Spotlight this post!  
Unread 17-02-2006, 14:07
Matt Krass's Avatar
Matt Krass Matt Krass is offline
"Old" and Cranky. Get off my lawn!
AKA: Dark Ages
FRC #0263 (Sachem Aftershock)
Team Role: Mentor
 
Join Date: Oct 2002
Rookie Year: 2002
Location: Long Island, NY
Posts: 1,187
Matt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond repute
Send a message via AIM to Matt Krass
Re: The silly syntax errors that won't go away!

Quote:
Originally Posted by xrabohrok
Alrighty. I am pretty new to C, though not that new, and I have decided to attempt to try making my own libraries and attached .c files to see how they work. Through much thinking, I have decided to make a program that would simulate a blackjack deck. What I have here isn't very flexible, and it just draws five cards. But when I compile, it says everything in the .h file has been declared twice! I don't know what to do! Here's the code:

main.c


deck.c



deck.h



the board didn't keep any of the formatting. Sorry!
This is a common problem. Your variables are being declared in every file that includes them. So use it more than once....it defines them in multiple files.

In the file that needs to own them, in this case deck.c, flank the include statement with
#define VAR_DECLARE
the include
#undef VAR_DECLARE

Then in your header file, wrap all the code declaring the variables in
#ifdef VAR_DECLARE
code goes here
#else
extern code goes here
#endif

After the else copy your code defining the variables, but put extern in front of each, that means to the compiler "This is already declared elsewhere, use that version."

Example:
C file that owns header:
Code:
#define VAR_DECLARE
  #include "header.h"
#undef VAR_DECLARE
C file that uses header, but does not own it:
Code:
#include "header.h"
Header file:
Code:
#ifdef VAR_DECLARE
  char myChar1;
  int myInt1;
#else
  extern char myChar1;
  extern int myInt1;
#endif
__________________
Matt Krass
If I suggest something to try and fix a problem, and you don't understand what I mean, please PM me!

I'm a FIRST relic of sorts, I remember when we used PBASIC and we got CH Flightsticks in the KoP. In my day we didn't have motorized carts, we pushed our robots uphill, both ways! (Houston 2003!)
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C18 v2.4 -- Syntax error where there is no syntax error Joel J Programming 7 12-01-2007 17:27
Union Errors in AutoCAD indieFan Inventor 4 16-07-2004 12:54
PBASIC language syntax WizardOfAz Programming 14 30-04-2003 10:23
Digital inputs, bandwith, errors? Micah Brodsky Programming 7 20-01-2003 16:08
Specs full of errors??? Simon G Motors 1 20-01-2003 12:53


All times are GMT -5. The time now is 16:54.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi