C/C++ :: Why Implicit Int Approach Taken With No Specifier Only For Global Variables

Sep 22, 2013

I realize that implicit int rule was removed in C99 but gcc still takes this approach by default. I wonder why this happens:

bbb = 5; // legal  
int main(void) {
  aaa = 10; // illegal
  auto aaa = 10 // legal

Inside function a specifier is needed. Error message with no specifier used is:

error: ‘aaa’ undeclared (first use in this function)

Is this because of linkage - bbb variable has an external linkage so compiler knows that we are defining a variable here while inside mean() we need to show compiler that aaa is defined right here, it does not come from external functions?

View 4 Replies


ADVERTISEMENT

C# :: Unable To Implicit Convert Type Int To String Though Declared Variables As String

Mar 26, 2014

Ok, so I'm writing this code and when I build it keeps saying cannot implicitely convert type int to string even though I declared my variables as string. Why is it giving me this error?

private static string Repair()
{
string result="";
string beep;
string spin;
Console.WriteLine("Does your computer beep on startup?:(y,n)");

[Code]...

View 3 Replies View Related

C :: Use Pointers Instead Of Global Variables?

Oct 15, 2014

I have made an application and I have basically solved everything. But the only problem is that I am using global variables because it felt like the smoothest, so my program is built on it.

But now I've read around and I understand that you should not use these(?). Do you think pointers is the best think to use instead?I have previously declared my board array and some variables as global and I want them in alot of functions.I have read and understand the procedure for the use of pointers so I can use my int's in the other functions by doing like this? Code: #include <stdio.h>

int justprint();
int main()
{
int Row = 2;
int Column = 2;
int *pRow = &Row;
int *pColumn = &Column;
[code]...

But how do I do it with an array like this one? If I declare it in the main function, and then want to use it in other functions.Or are there better, easier solutions?

Code: char game[3][3]={{0,0}};

View 13 Replies View Related

C++ :: Access EXE Global Variables From DLL

Jun 25, 2013

On linux, I can compile DLLs (shared objects) as well as executables that use them. I can even access globals and classes that are defined in the EXE from the DLL, and vice versa, simply with the 'export' keyword. flawlessly.

The Problem: But on Windows (using MinGW), no matter what I do, I'm completely unable to access global variables which defined in the EXE, from the DLL. On Linux, this is no sweat, but what's Windows' problem?

I also need to extend classes in the dll with base class method definitions defined in the exe.

Ive heard that on Windows, you need to use declspec(dllimport) and declspec(dllexport). I can compile with CygWin+MinGW/g++4.5.3 as well as "Pure Windows" with MinGW/g++4.7.2 *without* the declspecs. So what's the decljunk for? Is this really just something for MSVC or other compilers?

Here's some Windows code to show what the problem is. The DLL's global variable is accessible to the EXE just fine, but the EXE's global variable is not accessible to the DLL - compilation complains it is an undefined reference.

main.cpp
#include "myLib.h"
#include <stdio.h>
int exe;

[Code].....

edit: I tried using --enable-runtime-pseudo-reloc --allow-shlib-undefined options when compiling the DLL and G++ complains that --allow-shlib-undefined is an unrecognized option.

View 1 Replies View Related

C++ :: Setup Global Variables

Feb 23, 2015

I am using VS2010 to develop an app which includes several windows forms that I am trying to set up global variables for, and I am getting a few errors like:

LNK2005: "wchar_t *dsn"...already defined in ....obj

I have a header file (externals.h) with:
#ifndef MY_GLOBALS_H
#define MY_GLOBALS_H
extern long dbg;
extern wchar_t dsn[50];
extern wchar_t u[30];
extern wchar_t p[30];
#endif

and 2 different forms, each with different namespaces, but both including the above header (#include "externals.h").One of the form .h files defines the values for these externally declared variables like this: namespace PWValidationTools{

wchar_t dsn[50] =_T("MDOTProjectWise");
wchar_t u[30]=_T("api_admin");
wchar_t p[30]=_T("proce55");
long dbg = 1;

public ref class ValidationSetupForm : public System::Windows::Forms::Form {
}

The other form file only uses these variables, never defines them.I am getting the above LNK2005 error only for the variables declared as wchar_t, not the "long" one. why I'm getting the link errors only for the wchar_t variables.

View 1 Replies View Related

C++ :: Global Variables For Multiple CPP Files

Jan 19, 2014

I am trying to get variables that are global to multiple files. I have mananged to make constant variables that are global but maybe not in the best way. In the header i have the constant variables being defined:

const int variable_Name = 5;

And the cpp file:

#include <iostream>
using namespace std;
#include "vars.h"
int main ( ) {
cout << variable_Name<< endl;
system ("pause");
return 0;
}

Is there a better way to do this and to make the variables able to be changed within the cpp files.

View 7 Replies View Related

C++ :: Using Global Variables In Static Library

Jul 22, 2014

Is it possible to use & change global variables in a Static Library? For example:

I declare a
bool test = true;
globally.

Then later in an exported function If the user wants, he can set that test to false. So the program later when checks test if it's true, will notice that it's not true, since one of my function changed it.

Is it right?

View 3 Replies View Related

C++ :: Passing Data Between Threads Without Using Global Variables

Nov 6, 2013

I have a main thread and a worker thread. How do i pass data between them when both are already running without using global variables?

View 1 Replies View Related

Visual C++ :: Static Variables Local Or Global?

Mar 10, 2014

I came across the following code today and I was a bit surprised that it worked:-

Code:
std::string func_A () {
static std::string x;
if (!x.empty())
return x;

[Code] ....

I've simplified things slightly - but the basic point is that both functions are in the same source file and they both have a static std::string called 'x'. Being static, I guess they aren't (strictly) local variables. So how does the compiler know that they're different entities? Does it encode their signatures using the function name or something like that? If I call each function separately I do seem to get the correct string...

View 5 Replies View Related

C :: Compiling Sudoku Program - Declare Constant Instances As Global Variables

Sep 18, 2013

I am trying to compile a c program for sudoku. I have declare const instances as global variables, but when i try to compile the code it says that my declarations are not constant, here is some of the code.

#include <stdio.h>
#include <assert.h>

const int GRIDSIZE = 3;
const int GRID_SQUARED = GRIDSIZE * GRIDSIZE; //this line
const int ALL_VALUES = (1<<GRID_SQUARED)-1; //and this give//the error
int board [GRID_SQUARED][GRID_SQUARED];

View 3 Replies View Related

C :: Use Of Functions In Top / Down Approach

Mar 25, 2014

I'm getting a bit lost in calling functions correctly. The assignment says to, reprogram this assignment using functions and include the additional features identified below -

Design your program so the main function invokes/calls functions to perform the following tasks:

4) sort the arrays in ascending order by student ID number

Here's what I've got thus far and I'm confused cuz I might be calling my function incorrectly.

Code:
#include <stdio.h>
#define MAX_ENTRIES 50
void s_ID (int student_ID[], int test_score[], char char_val[]);
int main (void) {

[Code] .....

View 7 Replies View Related

C++ :: Good Object Oriented Approach To Meshing?

Aug 6, 2013

I'm a newbie to C++ and I've been working on this Delaunay tree in C for some time. I'm ready to port it to C++ which does not mean that the code itself is completed or done.

But I was wondering, how could I design my code to fully utilize C++?

For one, I'm using C++'s built-in stack/queue/vector functions because it's a lot nicer than building my own stacks or queues lol.

So, here's an overview of the code.

The mesh is built of tetrahedrons so I have a "struct tetra" which stores pointers to vertices ("struct particle") and its 4 neighbours. Working in half-plane data, we have:

Code:
struct particle {
double x, y, z;
};

struct tetra {
struct particle *p[4];//vertices
struct tetra *ngb[4];//neighbours

double a[4], b[4], c[4], d[4];//half-plane data
};

I'm fracturing these tetrahedrons by inserting vertices so I can get anywhere from 2 to 4 children per fracture per tetraheron. I'm mapping this history to a quadtree. This looks like :

Code:

struct tree {
int level;
struct tree *parent;
struct tree *children[4];
struct tetra *t;
};

What would be the best OO approach to this problem?

I thought about just using this object,

Code:
struct mesh {
struct tree *root; //pointer to root
/* insert all functions to be used by mesh here */
};

But I'm not sure how effectively this would be taking advantage of the OO paradigm.

View 4 Replies View Related

C++ :: Implicit Default Ctor - What Is It For

Apr 16, 2013

Implicit default ctor does not initialize the built-in data members, so what is it needed for?

View 5 Replies View Related

C++ :: Implicit Conversions To / From Library Type Only In Implementation

Apr 1, 2014

1. I designed two classes: Processor and Data.

2. Data represents some data object the user can pass to Processor's public methods.

3. Internally, Processor needs to use InternalData type which is based on the content of Data (I can use Data's public interface to get the required information from it, or construct a Data object using its public constructor when needed, and that's how I have done it so far).

4. To avoid repeating code and localize changes required when Data's interface would change someday, I made conversion functions from Data to InternalData and back inside Processor, as private methods.

Now here comes the kicker:

5. But I'd like these conversions to be implicit inside Processor's methods instead of explicit. And only there.

6. These conversion functions are only for Processor implementation's use. They shouldn't be visible nor accessible from the outside world.

Where the problem lays:

7. InternalData is a library type. I don't have control over it and I cannot modify its interface.

That is, I cannot just add converting constructors or conversion operator member functions to them.You can consider it to be built-in type if you wish.

8. I don't want to put those converters inside Data class either, since it's not its business and it shouldn't know that Processor converts it to something else internally.

Long story short, I'd like to teach the Processor's implementation how to make type conversions between Data and InternalData implicitly, but no one else except Processor should be affected by it. Outside world shouldn't be able to do these conversions or even know about them being done inside Processor's implementation.Is there any way to do it in C++?

The core of the problem seems to be the fact that in C++ defining implicit conversions is possible only from/to a user-defined type when defining this type. I don't know of any way to define such conversions for some other type's internal use only. (Especially when I don't have control about one of these converted types.)

View 6 Replies View Related

C/C++ :: Use Of Implicit Default Constructor Provided By Compiler?

Sep 21, 2014

In C++ if no user defined constructor is provided for a class the compiler automatically provides a implicit default constructor.

An implicit default constructor is equivalent to a default constructor with no parameters and no body ?

So what is the use of a implicit default constructor provided by the compiler, if it is not going to do anything ?

View 3 Replies View Related

C++ :: What Is The Type Specifier For Boolean

Dec 11, 2012

In the following example, how 'd I use sprintf when I have a boolean type of variable?

Code:
char s[64];
bool bVar = false;
sprintf(s, "This is a boolean variable bVar = %?", bVar);

What is supposed to replace ? in the sprintf statement ?

View 10 Replies View Related

C :: Width Specifier Does Not Align Like In Printf

Apr 19, 2013

I am currently debugging this function. I am trying to make this function's width specifier align like a printf() routine. Here 's the code:

v Code:
oid
bu_log(const char *fmt, ...) {
va_list ap;
struct bu_vls output = BU_VLS_INIT_ZERO;

if (UNLIKELY(!fmt || strlen(fmt) == 0)) {
bu_vls_free(&output);

[Code] ....

View 8 Replies View Related

C/C++ :: Read A Type Specifier From A File

Oct 28, 2014

I need to create certain objects which are listed in a file. So my code needs to run a loop and create objects(of type specified in file) and put them in a list.

It appears to me that type specifiers can't be replaced by string. Is there a way out ? I want following code to be working somehow.

#include <iostream>
#include <string>
using namespace std;

[Code].....

View 3 Replies View Related

C/C++ :: Expected Declaration Specifier In For Loop?

Mar 1, 2015

#include <stdio.h>
#include <math.h>
main() {
int n;
int k;
int j;
//gets user input for length of string
printf("Enter the value of n:");
scanf("%d", &n);

[code]......

When I compile my code I get an error saying that I need declaration specifiers in my is_prime subroutine in the for loop.

Here is the line of code it references.

for(j = 2; j < k; j++)

View 2 Replies View Related

C++ :: Access Serial Port - This Declaration Has No Storage Class Or Type Specifier

Feb 26, 2013

I am writing a code using Visual C++ to access serial port.

Code:
HANDLE hSerial= CreateFile(L"COM1", GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
DCB dcb = {0};
dcb.DCBlength=sizeof(dcbSerialParams);
dcb.BaudRate=CBR_1200;
dcb.ByteSize=8;
dcb.StopBits=ONESTOPBIT;
dcb.Parity=NOPARITY;

I am getting error in all last five lines in above code at dcb. and error is give below:-

Error: this declaration has no storage class or type specifier

View 2 Replies View Related

C++ :: How To Create A Global Object

Jan 18, 2013

if (choice ==1){
Light *myobj = new Light();
}
FlipUpCommand switchUp(*myobj);

Error: `myobj' undeclared (first use this function)

How to solve this problem without changing the Light class.

View 4 Replies View Related

C# :: Setting Global Hot Key On Second Form?

Jun 23, 2014

I created a WinForm app in C# using VS 2013 Express.

I added code to create a Global Hot Key on the main form. This works fine. My hot key is Ctrl-T. I can press the hot key and make the main form show and hide.

Then I created a second form (ChecklistForm) and now I want to press ctrl-T and make that form show and hide. I do not need the main form to do this any more. I just used the main form to test my Global Hot Key code.

So I'm having trouble getting the second form to respond to the hot key. When I put a break on the WndProc(), there is no break.

namespace ChecklistFSX {
public partial class MainForm : Form {
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(String sClassName, String AppName);
private IntPtr thisWindow;
private GlobalHotKeys hotkey;
public MainForm()

[code]....

View 2 Replies View Related

C/C++ :: Passing A Global Pointer?

Feb 29, 2012

Let's say I've got something like this:

struct Box{
//something
};
typedef struct Box* pBox;

[Code]....

function fun recieves the address(which is NULL) and then allocates the memory for the Box; Let's say I cannot return the address of new allocated p and I can't also use that pointer p(from main) without passing it into a function.

Q: How can I make it that I could operate in function "fun" as I operate on orginal pointer p(from main), right now I'm just passing the address to my function but I can't change the 'global' pointer p ;(.

I remember in pascal it's like:
"function(var pointer:[pointer to sth])"
and all is done.

View 14 Replies View Related

C++ :: How To Create Global Object

Jan 18, 2013

if (choice ==1){
Light *myobj = new Light();
}
FlipUpCommand switchUp(*myobj);

Error: `myobj' undeclared (first use this function)

How to solve this problem without changing the Light class.

View 9 Replies View Related

C++ :: Global Variable - Calling Sub Function

Dec 19, 2013

Expected output: 20

But what I got is: 22

Why. While calling sub function it should take the global variable am I right

insert Code:
#include <iostream>
using namespace std;
int a=0;
void sub()

[Code] ....

View 3 Replies View Related

C++ :: Updating Global Pointer In Tree

Jul 16, 2013

I am having trouble updating my global pointer in the following code,

Code:
#include <iostream>
using namespace std;

struct RB{
RB()=default;
RB(int clr):color(clr) { }
int color;

[Code] ....

The problem is, at line where I compar y==Tnil, It is evaluating to false at the first insert. But It should be true. again, after ending the function, T again becomes equal Tnil, as a result , none of the is being inserted.

View 2 Replies View Related







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