C++ :: Compile-time Loop Loops Wrong

Apr 10, 2013

Consider:
Code: template<unsigned int N>
class Test
{
private:

[Code]....

I just cannot understand why (clearly, we are calling <0, 0>, not <0, 8>). If I replace "N" with 8, it works as expected (at least for the beginning of the loop). I only tested on MSVC.

View 5 Replies


ADVERTISEMENT

C++ :: Possibility Of Compile Time Calculation

May 13, 2013

Is there any possible way of calculating some values at compile time? I have the following code of genereting upto 2000000010 palindrome numbers.

Code:
#include <iostream>
#include <string>
#include <sstream>
#include <string.h>
#include <stdlib.h>

[Code] .....

As you see, I have taken input from the user just after calculating the whole palindromes. So cant we calculate this at compile time? because runtime of this program is extremely slow.

Another qs. I first tried to use array but It didnt allow 2*10^9 sized array. so what should I do whenever I need that size of array?

View 12 Replies View Related

C :: Can Get Memory Addresses From Compile Time?

Sep 1, 2013

My question is this: Is it possible to determine where functions are stored at compile time, so that at run time you can pass the memory address as a pointer to the interrupt handler so that it can directly call the function at memory location 'X'?

The newest project I'm working on would require to either somehow capture these addresses or to find a work-around so that instead of passing the pointer to the interrupt handler, the software would then need to be able to be non-interruptable.

View 2 Replies View Related

C++ :: Compile Time Unique Identifier?

Jan 18, 2012

Would there be anyway for the compiler, or the language, to provide a unique ID during compilation?

I've been using UUID generators, but I've always found the approach of copy pasting from a program to code to be kind of... limiting. If I want a random number, can't the compiler guarantee this for me?

It already does the same thing for anonymous namespaces, so...

View 6 Replies View Related

C :: How To Exclude Function Dynamically On Compile Time

Mar 6, 2013

I am working on a project, where I have to be able to exclude some code fast and dynamicly at compiletime.

I got a scheduler running and actually I just want to remove some of the tasks from it - but at compile time so that the code wont take up space in my microcontroller.

I know that I can use macros like #ifdef #endif etc. But I think that method makes the code unreadable and complicated.

How to archive such functionality a more elegant way?

View 1 Replies View Related

C :: Library Of Functions - Getting Error At Compile Time

Nov 19, 2013

So I made a library for a whole bunch of functions and when i compile it, it says"Unresolved external symbol_(Name of function here) referenced in function main.

View 1 Replies View Related

C :: Possible To Create Char String At Compile Time?

Mar 28, 2014

I would like to have a program with a 5 mb string embedded in it kind of like this:

Code:

const char *c;
c = (const char*)"BEGIN_STRING_HERE, (5 MB of arbitrary values here)";

Is it possible to generate this string at compile time? Maybe with a macro? I'm trying to avoid a source file with a 5 mb string in it.

View 3 Replies View Related

C++ :: Set Array Size At Compile Time Through Constructor

Oct 22, 2013

How do I set the size of a member array via the class constructor if I know the size at compile time. I can do this with templates, see below, but this leads to code bloats, I think.

So one class declaration but objects with different array sizes.

Can't use constexpr.
Can't use STL.
Can't use new.

#include <iostream>
using namespace std;
template<int T>
class MyArray {
private:
int array[T];
public:
int getSize()

[Code] ....

View 15 Replies View Related

C++ :: Obtaining Operator From Compile-time Constant?

Nov 5, 2014

I want to generalize my productFunction below to a template family of functions where the template merely changes the * to + or whatever else operator I wish to use.

#include <iostream>
#include <functional>
#define show(variable) std::cout << #variable << " = " << variable << std::endl;
template <typename, typename...> struct ProductFunction;
template <typename RETURN_TYPE, typename FIRST, typename... REST>
struct ProductFunction<RETURN_TYPE, FIRST, REST...> : ProductFunction<RETURN_TYPE, REST...> {
const FIRST function;
using Base = ProductFunction<RETURN_TYPE, REST...>;

[code].....

How can I turn a template parameter into various operators? (apart from using switch statements that will reduce the performance and make the code really ugly) What kind of metatemplating method converts a compile-time constant to an operator?

View 3 Replies View Related

Visual C++ :: Compile Time Errors For OpensSSL In Project

Feb 4, 2014

I am trying to build a VC++ project in Visual Studio 2010. [URL] ....

This project has a dependency on openssl libraries. How can I successfully build this project? How to add third party libs/dlls in a project.

View 1 Replies View Related

C :: Correct Way To Initialize Typedef Structure In Compile Time (with Code)

Mar 6, 2015

Code:
typedef struct token
{
int tokenType; // what token is that
int tokenCode; // the code of a function if applicable
char *tokenString; // Source token
double tokenValue; // if token is a number

[Code] .....

I got several warnings and erros, is it possible to declare a table like that ? What's the correct way to declare it ?

View 4 Replies View Related

C++ :: Extracting From Loops - Run X Number Of Times And Produce A Prize Each Time

Sep 19, 2013

so i have a loop that will run x number of times and each time it will produce a prize which is a certain sum of money. I need to a way to sum all the money earned. I am thinking there should be a way to extract the prize one for each time the loop runs but i am not sure how to do that.

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

int main() {
cout <<"Option A: Drop one chip into one slot" << endl;

[Code] .....

View 2 Replies View Related

C++ :: Two Loops To Single Loop?

Jan 16, 2013

i have two loops ie.

if (n==null)
{
do loop 1
}
else //(n=!null)
{
do loop2
}

now i have to update the above code, with a single loop ie. when n==null or n!=null do the loop 1

how can i update.?

can i do like this
if(n==null ||n=!null)
{
do loop 1
}

is || operator above does the job what i expected

View 4 Replies View Related

C++ :: Create A Specific Number Of For Loops Each In Another Loop

Sep 18, 2014

I want to create a specific number of for loops each in another loop, as in example:

for(i=0;i<9;i++)
{
for(j=0;j<9;j++)
{
for(k=0;k<9;k++)
{
//some stuff
}
}
}

In this example there are 3 loops, but what if i want to create e.g. 10 such loops, and program reads a number of loops from a txt? It is needed for checking numbers.

View 2 Replies View Related

C++ :: How To Control Speed At Which A Loop Loops Based On Outside Variable

Feb 20, 2015

I'm using an animation program. In this program I've simulated a particle system. The particles are flying around at different and varying speeds. I've attached birds to the particles and I want to be able to control each bird's flapping animation based on its velocity; so birds moving faster will be flapping faster.

Initially, the bird's flapping animation is controlled by a parameter that goes from 0 to 100%. So not only do I need to drive the speed at which the animation goes from 0 to 100%, I need to set it on a loop so once it reaches 100%, it loops back to 0%. I'm extremely new to code so I don't think it would be wise for me to even provide a jumping off point, not that I could.

View 8 Replies View Related

C++ :: Print Each Percent Of Loop Breaks Down For Large Loops?

Feb 22, 2012

I'm trying to make a percentage counter inside a loop, printing each completed percent of the loop as it goes. I've managed to write such code, but when I run it the percentage output breaks down (becomes negative!) for large loops. I have an example below.

Code:
#include <iostream>
#include <sstream>
#include <string>
#include <stdlib.h>
#include <stdio.h>
using namespace std ;
int main() {

[code].....

Compiling and running the above yields the output:

Code:

...1% ...2% ...3% ...4% ...5% ...6% ...7% ...8% ...9% ...10% ...11% ...12% ...13% ...14% ...15% ...16% ...17% ...18% ...19% ...20% ...21% ...-21% ...-20% ...-19% ...-18% ...-17% ...-16% ...-15% ...-14% ...-13% ...-12% ...-11% ...-10% ...-9% ...-8% ...-7% ...-6% ...-5% ...-4% ...-3% ...-2% ...-1% ...0% ...1% ...2% ...3% ...4% ...5% ...6% ...7% ...8% ...9% ...10% ...11% ...12% ...13% ...14% ...15% ...16% ...17% ...18% ...19% ...20% ...21% ...-21% ...-20% ...-19% ...-18% ...-17% ...-16% ...-15% ...-14% ...-13% ...-12% ...-11% ...-10% ...-9% ...-8% ...-7% ...-6% ...-5% ...-4% ...-3% ...-2% ...-1% ...0% ...1% ...2% ...3% ...4% ...5% ...6% ...7% ...8% ...9% ...10% ...11% ...12% ...13% ...14%...100%

If I change the value of N to 1e7 instead of 1e8, the output is correct however!

Code:
...1% ...2% ...3% ...4% ...5% ...6% ...7% ...8% ...9% ...10% ...11% ...12% ...13% ...14% ...15% ...16% ...17% ...18% ...19% ...20% ...21% ...22% ...23% ...24% ...25% ...26% ...27% ...28% ...29% ...30% ...31% ...32% ...33% ...34% ...35% ...36% ...37% ...38% ...39% ...40% ...41% ...42% ...43% ...44% ...45% ...46% ...47% ...48% ...49% ...50% ...51% ...52% ...53% ...54% ...55% ...56% ...57% ...58% ...59% ...60% ...61% ...62% ...63% ...64% ...65% ...66% ...67% ...68% ...69% ...70% ...71% ...72% ...73% ...74% ...75% ...76% ...77% ...78% ...79% ...80% ...81% ...82% ...83% ...84% ...85% ...86% ...87% ...88% ...89% ...90% ...91% ...92% ...93% ...94% ...95% ...96% ...97% ...98% ...99%...100%

View 5 Replies View Related

C/C++ :: How To End A While Loop After Set Time

Feb 28, 2014

I am trying to make this while loop cut out / self break after 3 seconds. It is part of a simple game I am creating that gives the users 3 seconds to react otherwise it moves on to the next part.

while(1) {
key=getch();
if(key=='a'||key=='k'||key=='g') {
break;
}
}

All I need is it to end after 3 seconds, the rest of the code is working fine.

This sort of thing:

long startTime = System.currentTimeMillis(); //fetch starting time
while(false||(System.currentTimeMillis()-startTime)<10000)
If it IS for C, then I implemented it wrong or something.

View 10 Replies View Related

C++ :: Do While Loop Skips Over Input The Second Time Round

Mar 4, 2014

I don't understand why my Do While loop skips over the input the second time round?

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
using namespace std;
//prototype
string reverseInput(string *);

[Code] ....

View 2 Replies View Related

C/C++ :: Same Random Numbers Being Created Every Time Loop Goes Around

May 20, 2013

one of my project involves loop inside loops and creating random numbers. Here is what I have so far:#include <iostream>

#include <string>
#include <cstdlib>
#include <ctime>

[Code]....

so the program will create a random value for the inflow. The idea is that the internal for loop will continue to run until the fill_level of the reservoir, which starts at 0, hits the capacity. The process of simulating how many years (each iteration of the internal for loop representing a year) is to be repeated 10 times by the parent for loop of the water_level simulation for loop.

The problem is that the random number that is supposed to created are the same number. THey are different every time I run it, but they are the same every time the loops repeat to make a new simulation.

View 3 Replies View Related

C/C++ :: Finding Average Time Complexity Of A Nested Loop?

Oct 29, 2014

We were discussing how to find average time complexity of different algorithms. Suppose I've a the following nested loop

for(int i=0;i<n;i++)
{
min = i;

[Code].....

Now the outer loop will iterate N times. the inner loop will always iterate 3 times no matter what the value of N is. so the worst case time complexity should be O(n^2) but what about the average case and the best case? I mean in terms of searching we can figure out and distinguish between the worst,best and average as it depends upon the number of comparisons. But here how can the average and best case be different then the worst case.

View 13 Replies View Related

C/C++ :: Round Robin Execution With Gantt Chart - Arrival Time And Burst Time

Mar 10, 2015

This is a round robin execution. with gantt chart. arrival time and burst time. I think there is an error in my formula to get the right answer,i cant resolve it but my program is running. What is the code or the right formula??

#include<stdio.h>
int main(){
int i,j=0,n,time,remain,flag=0,ts;
int sum_wait=0,sum_turnaround=0,at[10],bt[10],rt[10];
int ganttP[50],ganttStartTime[50];
printf("Enter no of Processes : ");
scanf("%d",&n);
remain=n;

[Code] ....

View 2 Replies View Related

C++ :: Variable Assigned Wrong Value?

Nov 15, 2012

Consider the following:

Code:
float foo( float const *bar )
)
{
float temp;
temp = *bar;
...
}

Something I am noticing is that temp right after the assignment to *bar, is not the same value as *bar. This is for a project at work and the code runs on an embedded board with an ARM processor. I've copied the function into a standalone program for both Visual Studio and Code::Blocks and it works correctly there.

View 12 Replies View Related

C++ :: Fees Showing Up Wrong On Program

Feb 19, 2014

I'm writing a program that shows check fees for different amounts of checks. My other fees are showing up right but the .10 cents is not. It's showing up as .08 cents per check when I run the program.

Oh yeah the + 10 is for a $10 fee

Code:
else if (checks < 20 || checks >= 0) {
fee = .10 * checks + 10;
cout<< "Bank service charge for the month is $ " << setprecision(4) << endl;
}

View 3 Replies View Related

C :: Guess 4 Int Array With How Many Are In Right And Wrong Positions

Feb 11, 2013

For an assignment I have to create a random array of four integers, and then I have to allow someone to input up to ten guesses to guess the array in the correct order. I also need to be able to display whatever was generated by inputting -1. Finally, after every guess I have to tell the inputter how many of the guessed integers are correct and in the correct position, as well as how many integers are correct but not in the correct position.

So far I've been able to get the random array to generate properly, but inputting negative one has no effect, although if I input it four times in a row I get to my 'lose' condition. Also, it only seems to allow the user to input 4 guesses and not 10 before going straight to the 'lose' condition. I need to get these issues sorted out before I can move on to showing how many guesses are right etc....

Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
srand(time (NULL));

[Code] ....

View 3 Replies View Related

C# :: Des Encryption Produces Wrong Output

Feb 14, 2012

I have the following function:

Code:
public static void Des(byte[] key, byte[] inBuf, byte[] outBuf) {
if (key.Length != 8 || inBuf.Length != 8 || outBuf.Length != 8) {
throw new Exception("Des: Buffer or key length incorrect.");
}

DESCryptoServiceProvider des = new DESCryptoServiceProvider();

[Code] ....

I do not get the expected output of

Code: { 0x88, 0xBF, 0x0D, 0xB6, 0xD7, 0x0D, 0xEE, 0x56 }

instead I get

Code: { 0xC6, 0x61, 0x8D, 0x63, 0x0B, 0x39, 0x31, 0xB0 } am I doing something wrong?

I've even tried reversing the byte order of the test data, and I don't get the right result. I've tested the same data using C++ with CryptoPP on Linux, and I get the expected result, but I'm porting this code to run on .Net, and this is my main stoppage in the process at the moment.

View 5 Replies View Related

C :: Sensor Values Reading Wrong

May 24, 2014

My whole code is working but when the results are sent to my phone only the temperature value is reading correct the light value is all jungled up and moisture and pressure values are reading as 0.

Code:

#include "taskFlyport.h"
#include "grovelib.h"
#include "barometer.h"
#include <string.h>
extern BOOL incomingSMS;
extern int incomingIndexSMS;
extern BYTE incomingMemSMS;

[Code]...

View 4 Replies View Related







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