C++ :: Compiler Optimization And Num Accuracy?
Jun 11, 2014I 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 RepliesI 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 RepliesI 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] ....
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]...
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 */}})
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?
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?
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].....
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].....
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
[Code]....
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.
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.
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?
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....
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?
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++
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]....
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
how to download and install gcc compiler?
View 4 Replies View Related/*@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
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.
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?
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?
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"
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] .....
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;
}
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.