C :: Including Source File Twice But With Include Guard

Jun 14, 2014

I have four source files. The main source file includes two other source files. The two other source files both include the fourth source file. In the fourth source file I have an include guard. Will the code from the fourth source file exist in two locations in the compiled code? Is this something that is compiler dependent? An example of this is shown in the code below.

Code:

// filename: main.c
#include "source1.c"
#include "source2.c"

[Code]....

View 4 Replies


ADVERTISEMENT

C++ :: Including Header Files To Source File?

Jul 10, 2013

For example, I have the below files in a project called Calculate :

Source files : Calculate.cpp , Average.cpp (with out main)
Header files : Calculate.h , Average.h

I knew in general, we have to include Average.h to project header file Calculate.h to make it as part of project.

technical difference between adding header file (Average.h) to either project header file (Calculate.h) or project source file (Calculate.cpp) ?

I found no difference in an output. But, there must be technical difference.

View 3 Replies View Related

C/C++ :: Including Main Header File Which Includes The Including Head

Mar 28, 2015

I have a main.h file where I include all the needed things to make my program compile properly, string, vector etc.

And I also have another header file which comntains a class that is used later in the code (globally), I decided to keep it in another file to make it more clear and easier.

I need to include that file in main.h, but I also include main.h from that class header file because it contains some other includes that are required to compile.

Is this a good thing? Or should I keep main.h out of that class header file and include just things required for the class?

I may have complicated it too much, so I'll show an example, what I do now:

// ---- main.h ----
#include <string>
#include <vector>
#include <ctime>
// other includes, these are just examples
#include "MyClass.h" // the separated class header file

[Code] ......

So, from what you can see MyClass.h requires just including the vector, but to avoid repeating myself I include main.h which does that already, but also includes MyClass.h

So, I have two questions:
1. Is it ok to include in that way (including a file that includes the including file)
2. Is it good to include a main header file with all the includes even if I just need one of them, or should I skip including main.h and include just the things my class requires (vector is just an example)

View 2 Replies View Related

Visual C++ :: Including New Header File

Apr 22, 2013

I have the header (and accompanying lib file) in my project folder, I have it in my solution explorer. And I've tried to add it via C++ Directories.. but that doesn't seem to exist anymore, instead it points to a user property sheet, but where to find or access it ...

View 3 Replies View Related

C++ :: SIP Parser And Header File Including (using Sofia-sip)

Nov 6, 2012

I am currently developing a small quick'n dirty SIP (Session Initiation Protocol) parser. Its task is to read a file (or command-line argument) with a SIP requst and parse it using the sofia-sip library. It should exit either with "1" on parsing failure or "0" on parsing success.

I have taken the code snipplet from here: [URL] .... resulting in this source code:

Code:
#include <iostream>
#include <stdio.h>
#include <sofia-sip/msg.h>
#include <sofia-sip/msg_parser.h>
#include <sofia-sip/msg_mclass.h>
int main() {
char *msg_data = "...";

[Code] ....

When I try to compile the code using

Code:
g++ -o parser -I/usr/include/sofia-sip-1.12 parser.cpp

I get the following failure:

Code:
parser.cpp:10:45: error: "sip_default_mclass" was not declared in this scope ....

View 4 Replies View Related

C++ :: Include Function From Header File?

Feb 21, 2013

I am trying to include a function from a header file named headerfunt.h . The code of my header file is

Code:
#ifndef HEADERFUNCT_H_INCLUDED
#define HEADERFUNCT_H_INCLUDED
#include <iostream>

[Code]....

But, while compiling it says abs was not declared... I have included the file.

View 2 Replies View Related

C++ :: How To Include JPEG File Into A Program

May 3, 2013

How to include a jpeg file into a c++ program??

View 2 Replies View Related

C++ :: Unable To Open Include File?

Oct 16, 2013

my programme showing error 'unable to open inclde file ****' i fallowed the general procedure i.e., options-->directories--> ( inclde proper path) still not working..

View 2 Replies View Related

C :: How To Share Variable Value From One Source File To Other Header File

Dec 11, 2014

I wanted to share the value of a variable from Sender Program to Receive after program and want to calculate difference between send and receive. After studying Header file concept I program following three.

Now I am struck. How to to compile? I link all these file. I used following method:

Code:
gcc Sender.c -o Sender Sender.h
gcc Receiver.c -o Receiver Student.h

Then I run Sender and after that Receiver.I per my knowledge, Receiver should give difference but it gives error :

Code:
Receiver.c: In function "main":
Receiver.c:10:42: error: "Send" undeclared (first use in this function)
printf(" Total Receive is %d
",Receive-Send);

Code:
Sender.c
#include <stdio.h>
int Send ;
void main(){

[Code] ....

View 2 Replies View Related

C++ :: Source File And Header File Are Not Compiled Together

Jan 30, 2013

My socket.cpp program got error. it showed "socket.h: no such file or directory". I had put my header file (socket.h) in the same place with my source file.

View 1 Replies View Related

C :: Declaration Of Array In Another Source File

May 5, 2014

I was going through a code where i found the definition of int array[63] in one of the source files. But i also found the declaration as extern int array[66] in another source file. This is clearly wrong, but my doubt is how the compiler compiled it. It should have thrown error. In case if it compiles then what will be the behavior of the system? Will it be normal or some undefined behavior?

View 3 Replies View Related

C++ :: Making Exe File From Source Code?

Sep 4, 2013

I use a programming language called layout which nobody here has probably ever heard of. It was discontinued over 15 years years ago but it was a very visual & easy to use piece of software - no coding required. In fact once you name all the variables on cards (forms) from then on it's just mouse clicking & occassionaly typing a number if required. It used blackboxes in a flowchart arrangement which were pre-done code for doing just about anything. i.e opening windows, handling numbers & text, files etc. I have written many programs with it including database management, quoting software & currently use it in my business to track my jobs & do invoicing & ordering. It's a pity it wasn't updated & still around today.

[URL]

Back to the problem. Being a 16 bit program it was written to run on Windows 3.1 but still works on Windows 7!! as long as it is the 32 bit version. I need to write a program that will run on 64 bit W7 without resorting to using a virtual PC solution. I have tried to find something similar that I might be able to use instead but so far nothing comes close to Layout. I just remembered today that layout can produce not only .exe programs but also various versions of C/C++ including visual c++. So I got this idea that if I could get those files I might be able to stick them into a C compiler program to re-make a "modern" exe file.

I could just do a simple sample program & send the source code to them to see if it works on a 64 bit version of Windows 7. how I can do this myself to produce a working exe file.

View 5 Replies View Related

C# :: How To Get Source Path Of Selected File

Jun 5, 2014

how to get source path of selected file.

for example :

selected image in E:/

E:ewfolderillustration.jpg

application - asp.net(C#)

View 4 Replies View Related

Visual C++ :: How To Use A Different File For The Source In The Debugger

Nov 3, 2013

Visual studio 2012

I have a project that has a few .asm files (assembly language code), I have the compiler/assembler set to create a list file for the assembly code and would like the debugger to use the .lst file for the source instead of the .asm files because in the .asm files the macros are not expanded like they are in the .lst files which makes debugging difficult sometimes.

View 1 Replies View Related

C/C++ :: Program To Copy A File From Source And Paste With Different Name

Mar 6, 2014

I have written a program that copies a file from the source and pastes it there (same location), but with a different name. The program works fine, except there is a small bug that i can't seem to fix. Here is the code:

/*
This program copies a file from the current directory and pastes it to the same directory, but with a different name. The file name form the source must include the extension as well.
*/

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int main() {
char temp, s_file[100], d_file[100],

[Code] ....

This is the flow:

> 1) Enter the name of the file you'd like to copy (Must be from the current directory)
> A: 3.c // This depends if the file exists in the
> current directory
>
> 2) Enter the name of the destination file (The file will be copied to the same directory)
> A: 4 //The extension isn't necessary here
>
> Result: The file was copied successfully!

When I run the prg again, and this time input a file name with no extension, like this:

> Enter the name of the file you'd like to copy (Must be from the current directory)
> 3
> You did not enter a valid text. Press "?" to get help or "x" to exit.

I hit "?" and it takes me to

> 1. The file must be from the current directory)
> 2. The location mustn't be empty

Then it asks me

> Try again? (Y/N)

If i give N, it exits. BUT if I give Y, it goes, like this:

> Enter the name of the file you'd like to copy (Must be from the current directory)
> You did not enter a valid text. Press "?" to get help or "x" to exit.

You see, it doesn't give me the option to give it the file name..

View 3 Replies View Related

C++ :: Creating Another Source File In Console Application - VS Error

Jan 5, 2014

All I am trying to do is create another source file in a simple Visual Studio C++ console application.

I get the following errors:

intellisense: expected a delcaration
error C2447: "{" missing function header

I didn't create another int main () in this source file, so what is causing these errors.

View 1 Replies View Related

C :: Maintain List Of Variables Inside Source File

Apr 24, 2013

I'm about to begin work on an exercise that requires me to maintain a list of the variables inside a c source file. I'm trying to figure out how I'm going to pluck out the variable names from all the other noise. My first thought would be to count any word that isn't a keyword or other type of grammar syntax, such as parenthesis, brackets, semicolons, etc. right?

View 10 Replies View Related

C/C++ :: Placing Struct Of Object In Header And Source File?

Jul 19, 2014

Let's say I am using a library containing classes called class1 and class2 but both classes take three arguments to construct them. eg. class1(int a, int b, int c). and the same for class2

The below is an example of how to lay out the structure in the header and source file if class1 and class2 don't have any arguments in their constructor. But.... I'm not sure how to go about the below to take into account the constructor arguments of class1 and class2.

program.h
struct thestructure
{
thestructure(class1, class2); //constructor.

[Code].....

View 5 Replies View Related

C/C++ :: Compiling Source Code And Making Binary File

Apr 19, 2014

How to compile this source code and make a binary file

I think this need linux and run make command or gcc

This binary is a super user for android

source code attached

Attached File(s) : su.zip (7.59K)

View 3 Replies View Related

Visual C++ :: Game Controlled At Runtime By External Source File

Mar 24, 2013

Is it possible to create a program like Robocode, a game controlled at runtime by an external source file in visual c ++? For example create a checkers game where there would be an external source file, read at runtime, which would play automatically, with artificial intelligence. You can? If yes, how?

View 9 Replies View Related

C++ :: Including Outside Functions Into Classes?

Mar 6, 2015

I have a hpp file with a list of inline finctions like this:

Code:
inline int check() {
return 1;
}
inline int check_1() {
return 1;
}

... What I would like to do is to include them into several unrelated classes. How can I do this. Can I just add the hpp inline functions in headers of my class containing files or not. I mean if they are not defined as class functions how can they be called. I don't understan the logic.

View 2 Replies View Related

C++ :: Including Cocoa In A Program

May 13, 2013

I am running OS X Lion 10.7.5 and trying to include cocoa.

#include <iostream>
#include <Cocoa/Cocoa.h>
int main(int argc, char** argv) {
std::cout << "Hello, world!" << std::endl;
return 0;
}

When I attempt to compile the above code, I get several thousand errors, mostly "stray ‘@’ in program", coming from the cocoa framework. It compiles and runs correctly if I omit the cocoa include or if I name the file main.mm instead of main.cpp.

I'm pretty sure it's failing because cocoa is written in objective c and I'm reading it as c++ code..how to include an objective c file in a c++ program?

View 4 Replies View Related

C/C++ :: Including All Repetitions For One Turn

Feb 22, 2015

I am trying to include all repetitions for just one turn but I keep getting

00.0 but I want (the one in red)
170.3 0 0.3
180.0 17 0.0
190.3 18 0.0
200.3 19 0.3
210.0 20 0.3
220.0 21 0.0
22 0.0

so basically I call a function that represents just one turn of getting a random number, and then when the player decides he wants to get a random number that is at least 17 and wants to repeat this 3x I have to print out this chart that shows the chances of the player rolling the numbers between 17-22 [how many times does he get 0,17,18,19,20,21,22] this is what I have

cout << "your score: " << (' ') << "chances for that score:" << endl;
/* score is the player's total score for the one turn */
int score = 0;
int score0 = 0; // 0

[Code]....

View 3 Replies View Related

C :: Error Including Undeclared Structure

Aug 11, 2013

I get this error :

stra.c:54:29: error: "PS_index" undeclared (first use in this function)

and the function is

PS_Index = function(PS_index, indexData);

so what i am trying to do is :

first file:

Code:
#include <stdio.h>
#include <stdlib.h>
#include "stra.h"
int main (){
char name[] = "index.pif";
uint32_t i = 0;

[Code] .....

And header file:

Code:
typedef struct StraIndex{
uint32_t s;
uint32_t *i;
uint32_t *t;
}StraIndex; s

So first I would like to create my stra.o so i compile it as :

gcc -c stra.c -o stra.o

and then i get the above error. What would be the proper way to get a global structure inside my object.

View 2 Replies View Related

C++ :: Installing And Using Libraries (And Including Dependencies With Binaries)

Mar 4, 2013

I've worked a lot in Java and Perl and now I'm learning C++ and working on a simple e-reader (let's not get into why I'm not just using Kindle or other existing ones). This is for me and a number of friends.

At first my project will be on OS X, then Windows and Linux, and I hope to eventually use it on Android and iOS. I know that the last two will require separate GUIs, but I'm hoping the rest of the code will port easily.

Here's the problem:

I'm using Poppler to read and display PDF files. I started installing it on my iMac and it needs FontConfig, which is turning out to be a difficult install. I would not want to walk others through this or make them have to install Poppler and FontConfig (and any other libraries I find both need).

I thought I could just compile my final binaries using "-static" but I've been reading about how some libraries can't be statically linked or compiled.

Also, since I want to eventually port this to 4 other OSes (and apparently Poppler can work on those target OSes), I don't want to do something now or depend on something that will make it hard or impossible to port to other OSes later.

With that in mind, here are my questions:

1) Why is it some libraries cannot be compiled statically? How do I know if I'm dealing with one of those libraries?

2) Am I right that I could compile this program statically, and the resulting binary would include code from Poppler and FontConfig and other libraries would be included in the resulting executable binary?

3) What do I need to watch for so I can tell if using a particular library will be a problem when I need to port my program to a new OS? (Assuming, of course, that searching shows that library will compile or has been ported to that OS.)

View 7 Replies View Related

C++ :: Including Header Files Located In Two Different Directories

Oct 23, 2013

I have these two files:

/project/protocol/guarddog/report.h

/project/protocol/sky/report.h

I have two report.h files located in two different directories. However the contents of them are different. How can I include the report.h file located in guarddog into the report.h file located in sky?

I assume just doing this would be ambiguous:

#include "report.h"

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved