C++ :: Compiler Optimization And Num Accuracy?

Jun 11, 2014

I could not find anything I could understand on this, so I have heard that -O3 option may reduce the numerical accuracy of doubles. Is this true?

View 11 Replies


ADVERTISEMENT

C :: Calculate Value Of PI With The Accuracy (EPS) Given By User

May 23, 2013

I have to calculate the value of PI with the accuracy (eps) given by the user. I started with this but I just got stuck now, I don't know what is going on with the code or why does it get stuck in the second iteration...

PHP Code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(){    
float eps=0.000001; 

[Code] ....

View 4 Replies View Related

C/C++ :: Program That Calculate PI Based On User Input For Accuracy?

May 24, 2014

I am trying to create a program that will calculate pi based on a user input for accuracy. If the user input .3 then when the leibniz infinite sum value at a particular i becomes less then the input of .3 then the loop will exit.

I have looked at a number of examples on the internet but I feel lost. I have put together working code that will infinitely output sums but I need the loop to stop when the sum value is less then the accuracy value.

My question is what is wrong with my while loop, why will it only give me infinite summations? How do I make it so that the loop will exit when my accuracy input is greater then the sum?

int main () {
double accuracy;
cout<<"Give an accurate number." << flush;//looks nice
cin>>accuracy;
int d;//initialize denominator
double pi = 0.0;
while(accuracy < d){

[Code]...

View 8 Replies View Related

C++ :: Mixer Loop Optimization?

Nov 16, 2014

Can these loops can be optimized?

#define C_SAMPLEPOS(channel) (channel->sound.position)
#define C_BUFFERSIZE(channel) (channel->sound.numsamples)
#define C_BUFFERINC(channel) (channel->bufferinc)
//Use precalculated sample positions!

[Code]....

Should I change the inner loop (checking active channels and if they're valid) to the outer loop?

So the outer loop checks if the channel is valid for use, The inner loop checks and increases the current relsample The inner loop adds the sample to the mixer.

When the outer loop finishes: The outer loop clips all samples.

Would this be faster than the current method? (so instead of a:
for (sample=0;sample<4096;sample++){for (channel=0;channel<66;channel++){/* Process channel here */}}

We get:
for (channel=0;channel<66;channel++){for (sample=0;sample<4096;sample++){/* Process sample */}})

View 1 Replies View Related

Visual C++ :: How To Disable Optimization

Dec 27, 2014

I want to disable optimization in Visual C++ 2010. In gcc on Linux I could just use the -O0 switch, but in Visual C++ 2010 there are two categories of optimizations, one in the C/C++ pane and the other in the Linker pane:

Attachment 33229

So what settings should I choose to make sure that no optimization is being performed?

View 2 Replies View Related

C++ :: Null Statement - Prevent Optimization

Dec 7, 2014

Recently I was looking into embedded programing of AVR microcontrollers.

At this site [URL] ....

I have encounter some code that implements delay

asm volatile ("nop");

From what I understand it is assembler code that creates delay - one processor clock long.

For C/C++ language it should be like ; or {} = null statement.

Now my question is how to implement this C/C++ code and prevent my compiler (WinAVR: AVR-GCC) to delete this command during optimization (-Os or -O2). Or is it simply better to use the assembler function.

I know I can use for-loop

volatile uint8_t foo
for(foo=0; foo<2; ++foo){}

but for that I have to create a variable = wasting 1 byte of RAM; correct?

View 11 Replies View Related

C++ :: Rogue Like Item Creationg And Optimization

Mar 8, 2013

I'm creating a roguelike/ cave exploration game, and I've created a lot of it, but I am having problems with item creation. The item is supposed to be the '*'. I know what the problem is (I'm setting Dmap to map after creating the item, but before outputting Dmap), but I don't know how to fix it.Also, I don't really know how code optimization works.I'll split my code between this post and the comments:

#include <cstdlib>
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <stdio.h> /* printf, NULL */
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time *

[code].....

View 1 Replies View Related

C++ :: Binary Search Tree Optimization?

Jul 9, 2013

I was working on binary tree implementation and came up with this implementation. optimize this code?

/*
Binary Search Tree(BST)
06/27/2013
*/
#include "iostream"

[Code].....

View 3 Replies View Related

C++ :: Metal Cutting Parameter Optimization Program

Apr 3, 2013

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

[Code]....

View 3 Replies View Related

C++ :: Code Review For Empty Base Optimization Pair

Apr 10, 2014

I have tried to implement a much simplified version of boost::compressed_pair.What follows is a partially specialized EBO_pair<T1, T2> class template, written in C++11.The first type T1 is constrained to not be empty.The second type T2 may or may not be empty.

#pragma once
#include <memory>
#include <type_traits>
#include <utility>
namespace dsa
}

[code]...

Edit: added non-member swap() function template.

View 10 Replies View Related

C++ :: Using GNU GCC Compiler

Jun 9, 2014

I am programming with the Code::Blocks IDE and using the GNU GCC compiler. When I create an simple console application that uses strings it kind of glitches out, but here's the code:

#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
int main()
ered: " << x;

[code].....

What the output is:

Please enter a string of text: Hello World
You entered: Hello
Process returned 0 (0x0) execution time : 4.735 s
Press any key to continue.

Anyway I don't know why it removes what I typed after the space I put in between Hello and World.

View 1 Replies View Related

C :: Gcc Compiler And Pointers

Mar 3, 2013

The first sample program that I am reading on the book has the following code:

Code:

* Demonstrates basic pointer use. */
#include <stdio.h>
/* Declare and initialize an int variable */
int var = 1;
}

[code]....

Is this a compiler error or is there a proper syntax for pointers using the gcc compiler?

View 3 Replies View Related

C++ :: Class Not Seen By Compiler?

Sep 18, 2014

I have an issue. VS 2013 isn't recognizing objects that I've declared when I use class functions.I'm getting this error: "Line 14 and 15: Error C2228: left of '.asciiToFpc6' must have class/struct/union"...Here's the relevant code:

Source.cpp

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include "fpc6.h"

[code].....

Additionally VS apparently doesn't like my bitwise operators in my class functions and doesn't think they're doing anything. It gives "warning C4552: ['|', '<<', '>>', '&'] : operator has no effect; expected operator with side-effect" for all of them, but it seems to me the code should work fine and actually accomplish things....

View 9 Replies View Related

C++ :: Compiler Says There Is No Constructor But It Does Have One

May 29, 2013

Code:
activity = new Idle(this, NULL);
class Idle : public Activity {
private:
float mTimeInIdle;
public:
Idle() : mTimeInIdle(0) { }
Idle(Objects *actor, Goods *target) : Activity(actor, target)
{
}

Error 1 error C2514: 'Idle' : class has no constructors d:jackydocumentsvisual studio 2010projectsperfectsimperfectsimperfectsimObjectsObjects.h 43 1 PerfectSim

The activity = new Idle(this, NULL) line is located inside the Objects::Objects(...) constructor.

Would it be caused by some cyclic dependencies? How do I go about resolving it?

View 3 Replies View Related

C :: Compiler Keeps Freezing / Crashing

Feb 11, 2014

I wrote this code as an assignment

Code:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
main(){

int story, age=0;
int ranColor, ranCar, ranItem;

[Code] ....

And my compiler keeps freezing/crashing. using Dec C++

View 4 Replies View Related

C++ :: Compiler Not Recognizing Numbers

Sep 8, 2013

I'm working on this homework assignment where the program takes in the user's height in inches, weight in pounds, and age, then calculates their hat size, jacket size and waist size. The formulas for these are as follows:

Hat: (weight/height) x 2.9

Jacket: (height x weight)/288 then adjusted by adding 1/8 an inch for every 10 years over the age of 30 (The adjustment only takes place after a full 10 years, so there is no adjustment for 30-39, but there is for 40)

Waist: (weight/5.7) then adjusted by adding 1/10 of an inch for each 2 years over the age of 28 (the adjustment only takes place after a full 2 years, so no adjustment for 29, but there is for 30, etc)

I'm supposed to utilize functions for each of the three formulas.

There's a couple things I can't figure out.

1. Why won't the compiler recognize 2.9 and 5.7 as numbers?

2. How do I adjust the calculation for the jacket and waist based on age?

Here's what I've got so far:

#include <cstdlib>
#include <iostream>
using namespace std;
double hatSize(int weight, int height);
double jacketSize(int weight, int height, int age);
double waistSize(int weight, int height, int age);

[code]....

View 1 Replies View Related

C/C++ :: Compiler Configuration With Eclipse

Jul 7, 2014

I am using Eclipse to write C program. I download the CDT. However, I wrote the code but when I build it, I got an errors.

Make:*** No rule to make target all, Stop

View 10 Replies View Related

C/C++ :: Download And Install Gcc Compiler?

Jul 20, 2014

how to download and install gcc compiler?

View 4 Replies View Related

C/C++ :: Splint Warning In GCC Compiler?

Jun 7, 2012

/*@out@*//*@null@*/char *string_read ( ) {
int ch , pos = 0;
char *string;
if ((string = (char *)malloc (STRING_SIZE*sizeof(char))) == NULL)

[Code] ......

Fresh storage string not released before return A memory leak has been detected. Storage allocated locally is not released before the last reference to it is lost. (Use -mustfreefresh to inhibit warning) string_read.c:6:7: Fresh storage string created

View 1 Replies View Related

C++ :: Check If Compiler Has 11 Enabled?

Jan 28, 2012

Is there a way to check if a compiler has c++11 enabled?

I have a library and it has converters between std strings and the internal string type. I current have preprocessor surrounding the converters for u8string, u16string, and u32strings, but it requires the end user flip the switch manually. It would be nice if I could know at compile time without being told whether or not those types exist.

View 3 Replies View Related

C++ :: When Compiler Do Template Instantiation

May 2, 2014

As we know in the compilation stage, the compiler will instantiate a concrete type for a template, for example:

template<class T> void test(T m ) {
cout << m << endl;
}
int main() {
int kl = 0;
test<int>(kl);
}

In the main function, the compiler will try to have a int entry. Also we know that in the compilation stage, generally we have several steps: lexical analysis, syntax analysis, grammer analysis and intermediate language(IR).

So my question is: In which step is the instantiation done? Before IR or after IR?

View 1 Replies View Related

C++ :: Compiler Command Line Arguments

Jun 15, 2013

I have found this C++ online compiler (to use when I am at work): Compile and Execute C++ online

When you write and compile a program, on the right side (the "output" side), you can read this command line arguments:

$ g++ main.cpp -o demo -lm -pthread -lgmpxx -lreadline 2>&1

What is the meaning of the following arguments? -lm [link the math header file, right?]

-pthread
-lgmpxx
-lreadline

Any book (ebook, tutorial, printed book, whatever) where I can find all (absolutely all) these and other possible arguments?

View 2 Replies View Related

C++ :: Compiler Error C2664 And C2228

Nov 9, 2013

Working on a basic class program and I'm generating two compiler errors that I'm not sure how to fix. Header file, implementation cpp and main cpp are shown below. The specific errors are shown after the code.

Header file Code:

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

[Code].......

The file generates the second error, C2228, at lines 37-41 and 43. Basically where I tried using the second created object. Error message is "left of '.setFirstName' must have class/struct/union"

View 8 Replies View Related

C++ :: Compiler Error C2370 And C2011

Nov 29, 2013

Working on a solution involving inheritance. The whole solution is pretty massive at this point so I'll just focus on the problem areas. I'm getting a lot of "redefinition" and "undefined class type" compiler errors, including C2370, 2011, 2504, and 2027, in Benefit.h, Employee.h (the constant members are a big occurance) I'm also getting 2027 and 2079 in EmployeeMain.cpp. with my Benefit and Employee object calls.

Clearly I missed something in about how to code this correctly. Sadly the course textbook focuses on general OOP theory instead on the accompanying C++ syntax.

Benefit.h
Code:
#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
using namespace std;

[Code] .....

View 4 Replies View Related

C :: Determine Compiler Version And Which Standard It Uses?

Jul 18, 2013

Is there any code I can use to determine my compiler version and which Standard It uses? I know the following code determine that my compiler followed ANSI But how about a version of that? ****My OS is now Ubuntu

Code:
#include <stdio.h>
int main(void){
printf("File :%s
", __FILE__ );
printf("ANSI :%d
", __STDC__ ); //return 1 if it follow ANSI but version?
return 0;
}

View 3 Replies View Related

C :: Does Compiler Only Check Qualifiers Of End Destination

May 28, 2014

Code:

#include <stdio.h>
#include <stdlib.h>

const int* const ret_con()
{
typedef const int* const cip_to_c;
}

[code]....

I have two basic questions about what is happening:

1. The return value of ret_con should be pointing to const, but instead it's pointing to a (non-const) pointer to const. Does the compiler only check the qualifiers of the end destination, why doesn't this give a warning?

2. The original variable from ret_con (ci) is a local automatic, shouldn't its lifetime have expired when you leave the scope?

I also checked this with C++ compiler (taking out the auto keyword), it gave no warnings either.

View 4 Replies View Related







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