C :: Testing If A Macro Is Defined To A Value?

Jan 16, 2015

Say I have something lke

Code:
#define FOO BAR
#if FOO == BAR
doX();
#else
doY();
#endif

This causes doX(); to be executed. But the intent is to have doY(); be run. I'm guessing this is because BAR is undefined and therefore blank, so blank equals blank. Is there some way to compare the symbol FOO was set to instead of its value, BAR?

View 4 Replies


ADVERTISEMENT

Visual C++ :: Unit-testing Functions With User-defined Types?

May 4, 2013

How can we build unit-tests for functions of libraries, those with user-defined types used as their arguments ?

For example

CRecord func(Myclass * class, BSTR * name, CComptr<xxx> & something);

View 9 Replies View Related

C++ :: Define A Macro Within A Macro?

Feb 26, 2012

Is it possible to define a macro with in a macro? Any trick will do. I am trying to do quick conversion of cuda program to open mp by defining some macros at the top:

Code:
#define __syncthreads() #pragma omp barrier

View 2 Replies View Related

C++ :: Testing Conditions For Consistency

Dec 1, 2013

In the below program, when we have 4 consecutive spaces, the following comparison will not be equal: (x / tabstop != (x + spaces) / tabstop). If we have, let's say, only 2 consecutive spaces, then the comparison will be equal. So we know to print a tab with 4 consecutive spaces and not print a tab otherwise. How do we know this kind of division comparison would work in every case?

#include <stdio.h>
#define TABSTOP 4
int main(void) {
size_t spaces = 0;
int ch;
size_t x = 0; /* position in the line */
size_t tabstop = TABSTOP; /* get this from the command-line

[Code] .....

View 3 Replies View Related

C++ :: Testing Cos - Why Angle Is Not 45 Degrees

Apr 25, 2012

I developed this simple sample program to test cos():

Code:
#include <cmath>
#include <iostream>
using namespace std;
int main() {
const float radiansToDegrees = 180.0f / 3.141592653589793f;
float c = sqrt(2.0f);
float a = 1;
float angleRadians = cos(a/c);
float angle = radiansToDegrees*angleRadians;
}

I expected angle to be 45 exactly, but it's value is: angle = 43.558804

Why is the angle not 45 degrees? What did I do wrong?

View 4 Replies View Related

C++ :: Testing Object Against All Other Objects In Vector?

Jan 28, 2015

I'm working on collision detection for a game in SFML. I successfully designed a Spatial Partition grid to speed up the collision test, in the following of this tutorial: [URL] ....

But now I have an issue with one aspect of it: Going through a vector of objects and testing all the OTHER objects in the vector against said object. The author puts it into psueudocode here:

For each tick of the clock

For every object in the game

Get all the other objects in the same grid square

For each other object in the same grid square

I have trouble with the last line, because in iterating through a vector I am not sure how to skip over the current object. Here is my own code (a couple of sysntax errors but this is a c++ question not an SFML question):

//for every moveable object
for(int i = 0; i < rects_.size(); i++){
std::vector<sf::RectangleShape> posibleObjects_; //this will be a vector of WorldObjects in a real game
//for every object in that object's gridsquare
for(int j = 0; j < rects_.size(); j++){
if(rects_[i].intersects(rects_[j])){
//collision
} } }

The problem is, a collision will always be reported because somewhere in the vector the object will eventually check against itself which is always a true collision. What is the correct way to do this?

View 11 Replies View Related

C++ :: Testing For References To Identical Objects

Jun 18, 2014

I am checking to see if two references are bound to the same object. My instincts tell Me, "Check their addresses. If they match, they are bound to the same." At the same time, I have not found anything in the C++ standard which would support this approach. Am I missing something? Is there wording which backs up My instincts? Is there a standard function to do this?

View 4 Replies View Related

C/C++ :: Testing String Against Array Of Char

Apr 3, 2013

I have a text file with state names, and state abbreviations, thusly:

ALASKA
AK
ARKANSAS
AR
..and so on.

I have to load the abbreviations ONLY from the file into an array of char[ - (already done and tested).

I have to get a 2 char abbreviation as a string,then test it against the state array to make sure it is a valid abbreviation. As it stands, my test is never finding an invalid abbreviation..

Here is where I get the input:

void getState() {
char state[10];
getString("Please enter the state as a 2 char abbreviation:",state,10);
printf("State Entered:%s", state);
validState(state);

[Code] ....

View 14 Replies View Related

C/C++ :: Testing To See If User Input Is A Number

Feb 10, 2013

I was wondering what function was the C++ equivalent for testing to see if a user input is numeric.

I have equivalents in Ruby, Java, Python, VB, VBA, php, but being a novice in C++, I have yet to find one - even with Google.

And I know C++ is such a wonderful language, that its extensive library must have one somewhere - considering it's already 2013!

View 2 Replies View Related

C++ :: Testing HTTP Headers - For Loop And Strings

Jun 23, 2014

I am testing HTTP Headers and I have an strange problem. When I get the response of the server, it is the correct one the first time. If I use a for loop to send more than one request and get more than one response, this response seems to be overlapped with the previous ones. To a better explanation of the problem I attach the code I am using and the output generated:

TCPSocket.h
-----------
#ifndef _TCPSOCKET_H_
#define _TCPSOCKET_H_
class TCPSocket {
private:
int localSocket;

[Code] .....

So, a bigger loop, a bigger the response of the server. However, I know the response of the server is always the same.

View 3 Replies View Related

C# :: Testing Devices For Up / Down Status On External Network?

Jul 11, 2014

I know I can use ping internally to test a device's connectivity. What can I use to test devices on another network (assuming ports are forwarded, and their IP addresses are at my disposal)? I was looking into the TCP Client class.. would that also work with devices using DynDNS?

View 7 Replies View Related

C :: Program For Infinitely Looping After And Testing For Active Process

Mar 23, 2013

What I have: A basic program for infinitely looping after and testing for an active process. It has a delay system built in to make it so it is not constantly iterating.

What I need: A way to get process IDs from other Processes other than my program. With a way to use that ID to detect if that process is active on the computer or not.

Parts of my code that need changing:

/* Code for handling the process would go here */

/* Code for detecting the target would go here */

What the goal of my program is: Perform operations to terminate the process of cmd.exe when it is active on the user's computer. Then output the status of the process and the time it took to find that process to the user.

It contained functions that I needed, but I need more information on how to apply them to other processes instead of the parent of my program and its' children.

Here is the code I prewrote for this so far:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define ZERO 0
#define INFINITE 1000000000000000

[Code] .....

View 1 Replies View Related

C :: Testing Random Numbers And Prepare Histogram With Each Number

Dec 30, 2013

I have to make program which can generate a lot of random numbers and than prepare histogram with each number. Histogram must look that:

0 ( 50):*****************************************
1 ( 59):********************************************** ***
2 ( 42):***********************************
3 ( 49):****************************************
4 ( 41):**********************************
5 ( 53):********************************************
6 ( 60):********************************************** ****
7 ( 47):***************************************
8 ( 54):*********************************************
9 ( 45):*************************************

View 14 Replies View Related

C :: Testing Array Functions - Return Sum And Difference Of Two Matrices

Nov 10, 2013

I have these arrays in a driver to use for testing:

insert Code:

#include <stdlib.h>
#include <stdio.h>
#include "TwoD.h"
int main() {
/* Initialization of LCV's */

[Code] ....

If I want to test these functions in this header:

insert Code:

#ifndef TWOD_H_INCLUDED
#define TWOD_H_INCLUDED
#define MAX_SIZE 50
/* Structure defenition for TwoD */
typedef struct

[Code] ....

I am trying to perform columnSum and rowSum, as well as twoDadd and twoDSubtract using the arrays defined in my driver. How would I do that using A and B in my driver?

View 8 Replies View Related

C :: Defining And Using A Macro

Jan 4, 2015

I am trying to create a small set of filepath functions that I intend to compile across linux and windows (I prefer not to use a big library). I want to have a global constant PATH_SEPARATOR that depends on the OS environment. This is what I set at the top of header file.

Code:

#include <stdio.h>
const char PATH_SEPARATOR =
#ifdef _WIN32
'';
#else
'/';
#endif I was hoping to test this while compiling this in a linux environment using gcc, thusly:

Code:

int main (int argc, char const* argv[])
}

[code]....

where apparently, I seem not to be able to "set" a part of the code to have "_WIN32" defined. I don't know if I explained this clearly.

View 5 Replies View Related

C++ :: Macro To Template?

Mar 22, 2013

I have this macro, that expands to some methods of my class:

Code:
#define POPULAR_COMBO_FILTRO_COM_BASE(classeTabela)
void VisualizadorLogsFrame::PopularComboFiltroCom ## classeTabela (bool limparTexto) {
long from, to;
m_cbxDetalhe->GetSelection(&from, &to);

[Code]...

but I get a compile error on this line:

Code:
for (list< CLASSE_TABELA *>::iterator linha = lista->begin(); linha != lista->end(); linha++) {

what am I doing wrong ? the error is:

VisualizadorLogsMain.h:174: error: expected ';' before 'linha'
VisualizadorLogsMain.h:174: error: 'linha' was not declared in this scope

View 4 Replies View Related

C :: Variadic Macro Function

Sep 12, 2013

I'm doing right now is creating a function that callocs (I prefer this to malloc) and returns a string, and it will work similar to printf, I'm calling the function alloCpy(),I have several values that I need in a malloced string, so I call Code: myAllocedString = alloCpy("Value 1 is %s, value 2 is %s, and value 3 is %d", str1, str2, num); To do this I'm using the Variadic Macro, the reason I'm not just using a Variadic Function such as this: Code: char* alloCpy(char *format, ...) {} is because I need to append NULL to the end for the sake of looping through arguments, and I'm understanding it thusfar, but I have a few issues, first of all, I tried defining the Macro in a header file, but when I try to call it I get the error "Undefined reference to alloCpy". Also, to loop through arguments to get string lengths I'm using va_arg(args, char*) which requires all the arguments to be of type char*. Here is my code:
myheader.h:

Code:

#define alloCpy(format, ...) _alloCpy(format, ##__VA_ARGS__, NULL);
char* _alloCpy(char *format, ...); mycfile.c: Code: char* _alloCpy(char *format, ...) {
va_list args;
va_start(args, format);
int args_len = 0;
}

[code]....

So, how can I do this to, first of all, make my macro function accessible from other files importing myheader.h, and second, how can I make it accept any type of argument like printf, so that my example above would work?

View 3 Replies View Related

C++ :: Replacing Macro With Constant

Apr 4, 2013

I heard that const shall be preferred over #define . So I start to change my program accordingly.

But then below error message occurs during compilation:

#include "common.h"
#include "definition.h"
#include "particle.h"
int main() {
Particle *p = new Particle();

[Code] .....

I guess the error occurs because, when the line 9 of particle.h (File 4) is compiled, value of const int dimension is not seen by the compiler.

View 6 Replies View Related

C/C++ :: Migration Of Serialization Macro

Jun 12, 2014

I have to migrate C++ source which is compiled with MinGW-gcc to be compiled with VS2013, and have one issue with one macro used for serialization.

Here is macro:

#define IMPLEMENT_SERIALIZE(statements)
unsigned int GetSerializeSize(int nType, int nVersion) const
{
CSerActionGetSerializeSize ser_action;
const bool fGetSize = true;

[Code] ....

Here is place in code were it is call (in class declaration):

IMPLEMENT_SERIALIZE(({
if (!fRead) {
uint64 nVal = CompressAmount(txout.nValue);
READWRITE(VARINT(nVal));

[Code] .....

When compile received errors:

main.h(555): error C2059: syntax error : '{'
main.h(555): error C2143: syntax error : missing ';' before '{'
line 555 is end of macro call ( "})").

How should look using of this macro in order to avoid that errors?

View 7 Replies View Related

C++ :: Pitfalls Of Macro Substitution?

Dec 29, 2013

"If you examine the expansion of max, you will notice some pitfalls. The expressions are evaluated twice; this is bad if they involve side effects like increment operators or input and output. For instance, the below example will increment the larger twice."

#define max(A, B) ((A) > (B) ? (A) : (B))

max(i++, j++)/* WRONG */

I don't see what the problem is with the code above. i is incremented and j is incremented and then it performs a ternary operation to see which is greater. Am I missing something?

View 1 Replies View Related

C++ :: Two Projects - Defining Value Of Macro

Jun 27, 2012

Say I have two projects A and B. A depends on B. If project A defines a macro to be 100 and project B defines the same macro to be 200. In project A, if I use this macro, what value would this macro be? Let's just forget macro is evil for the time being. Let's also forget that it is not good to define the same macro twice for the time being.

View 8 Replies View Related

C :: How Macro Works To Concatenate Three Integers

Nov 15, 2014

when i was finding a way to concatenate three integers in C, I came across a snippet like this

Code:

#include<stdio.h>
#define cat(a,b,c) a##b##c
int main()
{
int d;
d=cat(1,2,3);
return 0;
}

How the macro works here? I am unable to understand the function '#' plays in the macro.

View 1 Replies View Related

C :: Writing A Macro That Returns A Boolean Value

Apr 24, 2014

I need writing a macro that would return true/false (1/0) )value. I want to check if a certain element exists in the array. The macro will accept array, its size, and the value to be compared, and must return yes or no. Here is the code that I have written:

Code:
#define EXISTS(T, a, n, val) do {
char ret=0;
T *a_ = (a);
size_t n_ = (n);
for (; n_ > 0; --n_, ++a_){
ret = (*a_ == val);
}
}
while(0)

How can I get the result from this macro.

View 6 Replies View Related

C++ :: Macro For Changing Array Size

Nov 22, 2013

I'm trying building a new macro for change the array size:

#define redim(varname,x) ((sizeof(varname)*) realloc (varname, x * sizeof(varname)));
int b;
redim(b,3);

error message:
"error: expected primary-expression before ')' token"

what isn't right with these macro?

View 10 Replies View Related

C++ :: Linking To Static Library That Contains A Macro

Jul 16, 2014

I have built a static library that contains a macro. From a separate exe, I am calling this macro, but it doesn't work.

The compilation of the static library and that of the exe went okay.

Static lib contains just the macro definition.

Exe contains call to this macro.

Is there anything else that I need to do for this to work?

View 4 Replies View Related

C# :: Command To Attach A Macro On A Process?

Jan 20, 2014

i would like to know if its possible to use a c# command to attach a macro ( JitBix MacroRecorder ) so it would send keystrokes while the process/program was minimized. i've tried with [lapeiro, on 20 January 2014 - 06:43 AM, said: i would like to know if its possible to use a c# command to attach a macro ( JitBix MacroRecorder ) so it would send keystrokes while the process/program was minimized.

View 4 Replies View Related







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