C :: Possible To Make Compiler To Generate Smarter Code
Mar 6, 2015
I am not a C programmer (or a programmer at all). I am just a hobbyist who writes random code (i.e.: ignorant).C is not my area, and I my experience with it is quite LIMITED!Today, I found out that if I need to get "square root" in C I will be in trouble if I depend solely on the compiler..Is it possible to make the compiler to generate smarter code for this (quite trivial code):
Code:
void intprime_c(unsigned long* fprimes, unsigned long count)
{
unsigned long divc = 3;
unsigned long num = 2;
unsigned long sqr;
unsigned long pfound = 0;
}
[code]...
By "without ugly hacks" I mean using already existing code that came with GCC. Because the others did not need ugly hacks to perform better (it is all about being fair).To compute the "square root" in x86 one just need 3 instructions:
fild
fsqrt
fistp
But the compiler is generating a call to a "fsqrt" function and wasting a lot of time by doing this. If not, then why is it taking so long? Is it something wrong in my code (at least the output was verified to be the correct)?
Time taken to get the first 2500000 primes (x86_64):
Assembly = 72.400s (human written, unoptimized, coder level: newbie (i.e.: ignorant))
pascal = 75.200s (written by the same person)
C (fsqrt) = 83.600s (written by the same person)
C (sqrt) = 85.900s (written by the same person)
If it matters, I compiled the C code with this command: gcc -O2 -fno-omit-frame-pointer -fPIC -c ./prime.
View 7 Replies
ADVERTISEMENT
Apr 14, 2013
This: "The compiler may not always be able to insert the code for a function inline (such as with recursive functions or functions for which you have obtained an address), but generally, it will work."
For a function inline why wont it work for a recursive function or a function for which you have obtained an address?
Why cant the compiler still insert the inline?
View 4 Replies
View Related
Jan 26, 2015
This program works on an online compiler but force closes on codeblocks after entering the elements.
#include<iostream>
using namespace std;
int two_print(int x, int one[999]) {
int two[999][999];
for(int k=0, r=x; k<=x; k++, r--)
[code]....
View 6 Replies
View Related
Feb 20, 2014
I have an application thats has been coded in C#. After build it generates a standalone dll file and the exe file.
I want to use this code in Matlab. I found out from this page that I can load the C# classes or codes into Matlab.
dll_in_matlab = NET.addAssembly('location to the dll file)
I have the code and the application buty unfortunately I do not understand C# at all. So after using this command I was able to see a .NET object in my workspace and this is what I got for its properties and its classes:
evmaps =
NET.Assembly handle
Package: NET
Properties for class NET.Assembly:
AssemblyHandle
Classes
Structures
Enums
GenericTypes
[code]....
This is the application it produces: [URL] and here is the virustotal result for my application just to ensure that its clean. [URL] .....
View 1 Replies
View Related
Apr 23, 2013
i wanna no if i can make the program generate a different number everytime you guess the number right and want to play again. it always generates the same number
#include <iostream>
#include <ctime>
#include <cstdlib>
[Code].....
View 9 Replies
View Related
Mar 11, 2013
Why does the following line of code generate error as " pasting / and / doesn't generate a valid reprocessing token"?
Code:
#define comment /##/
int main() {
comment printf("hello");
return 0;
}
View 2 Replies
View Related
Aug 20, 2013
Theres a class named "A" which has got a static function named "sfA".Now I instance an object of class A and call a method from A called "fA".
The method fA calls sfA. And now the issue is: i need the value of a member from the object which called fA respectivly sfA, inside sfA.Is there a smarter way to get the value of the member as to declare an new parameter for the sfA? sfA has to be static.
View 4 Replies
View Related
Jun 10, 2013
How to make a source code into a functional program that a user can open and use without coming across the source code and building or running it.
View 1 Replies
View Related
Mar 29, 2013
(C++ question) I need to be able make a compiled code (like a .dll?) which other programmers can use on linux, win,, mac, etc.
The compiled code would simply do calculations and spit out an answer in memory.
I need it to have certain functions that they can easily call and understand (without actually seeing the source).
View 2 Replies
View Related
Aug 10, 2014
This code compiles in release mode but I get this compile error in debug mode:
Error1error C2664: 'GetPrivateProfileStringA' : cannot convert parameter 4 from 'wchar_t [255]' to 'LPSTR'g:easywebstoreuploaderini.cpp45
Code:
CString CIniFile::getKeyValue(CString strKey, CString strSection) {
wchar_t ac_Result[255];
// Get the info from the .ini file
m_lRetValue = GetPrivateProfileString(strSection, strKey, _T(""), ac_Result, 255, m_strFileName);
CString strResult(ac_Result);
return strResult;
}
View 3 Replies
View Related
Oct 18, 2012
I need to have Ufasoft Miner source code modified so it's rendered undetectable to antivirus software. The source code is located here: [URL]
It's programmed in C++.
We have other unrelated projects after this, that you might apply to.
View 2 Replies
View Related
Apr 15, 2013
I have assignment which requires me to print out and array code and a pseudo code. I dont no what a pseudo code is,.
View 2 Replies
View Related
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
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
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
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
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
View Related
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
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
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
Jul 20, 2014
how to download and install gcc compiler?
View 4 Replies
View Related
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
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
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
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
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