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


ADVERTISEMENT

C# :: While Statement Not Recognizing Non-null String

Oct 10, 2014

The List[] array contains some empty entries but most are filled, yet every time I run this routine the variable Index makes it to the end of the array. I've tried many different routes and can't seem to figure out this simple issue.

string Result = string.Empty;
while ((Index < (List.Length - 1)) || !string.IsNullOrEmpty(Result))
{
Result = List[Index];
Index++;
}
return Result;

View 9 Replies View Related

C++ :: Null Terminator Same As Null And Through False Value?

Feb 18, 2014

I am looking at one of the functions of an exercise:

void escape(char * s, char * t) {
int i, j;
i = j = 0;
while ( t[i] ) {
/* Translate the special character, if we have one */
switch( t[i] ) {

[code]...

Notice the while loop evaluates the current value in t to true or false. When we hit the null terminator, does that get evaluated as 0 and hence evaluates as a falsy value so the while loop exits?

View 1 Replies View Related

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 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++ :: 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# :: Session Is Null But Not Null?

Mar 31, 2015

When you login to my site my loginservice which is done by ajax and json make a session called context.Session["Name"]. With BreakPoints it shows that everything is good and the variables are in place. However when I use Session["Name"] it comes out as null.

I will add my code at the bottem not

using System;
using System.Collections.Generic;
using System.Linq;

[Code].....

View 2 Replies View Related

C++ :: How To Prevent Loop Running Over

Feb 18, 2014

i am writing a function that takes a delimited string and splits the strings into it's respective words according to the delimeter.

1) iterate through string and store delimeter position in vector array.

2) iterate through again and use substr to split into words and store again in a vector.

I then have a dictionary file, and am comapring each values in the string with each in the dictionary, problem is that it overruns the loop and obviously gives a subscript out of range error.

Code:
#include <iostream>#include <fstream>
#include <vector>
using namespace std;
//Start with string inputString
//Find delimeters ::pos as ints and stores positions in vector <int> array
//Run though string using 'find' and seperate string by positions of char32s
//Build vector<string> array of individual words in string
//Open dictionary file and loop though testing each words in vector string array against each word in dictionary

[code]....

View 4 Replies View Related

C :: Prevent Duplication When Insert Age

Oct 17, 2014

I created program that insert employes data and then print their data but never accept duplicate age if user entered duplicated age prompt him to enter another age (age must be unique)

Code:
#include<conio.h>
#include<stdio.h>
#define size 3

struct emp
{
int age,overtime,dedcution,netsal;
float salary;

[Code] .....

View 3 Replies View Related

C :: Prevent To Type Zero As The First Digit In Value

Apr 4, 2013

I want to prevent to type zero as the first digit in value in c code

Code:
char next_buffer[ 5 ];
int frame_counter;
int digit_counter;
memset( cmd->next_buffer, 0, sizeof( cmd->next_buffer ) );
cmd->frame_counter = 0;
cmd->digit_counter = 0; Code: if( arg && isdigit( arg[ 0 ] ) {

[Code].....

this write in text box numbers from keypad for example

5 0 2 4 9

After each typed digit, here is a underscore line waiting for the next to type next digit. I want to prevent users to type zero as the first digit in value.

View 4 Replies View Related

C++ :: How To Prevent The Main Thread From Blocking

Feb 14, 2014

I have an issue where I iterate through devices and make driver API calls. Unfortunately, these calls take too much time and they are interrupting my real-time scheduler. I have 12 cores, of which one is 100% and the others are < 1%.

I'd like to multi-thread this thing. So far, I've replaced:

for (DeviceIterator d = devices.begin(); d != devices.end(); ++d) {
d->Write(words, numwords);
}

with

void* ThreadedWrite(void* p) {
WritePackage* wp = (WritePackage*)p;
wp->device->Write(wp->words, wp->numwords);
delete[] wp->words;
delete wp;

[Code]...

My problem is that this didn't improve performance at all. The main thread still takes too long to execute. Is there something I need to do to prevent the main thread from blocking?

View 2 Replies View Related

C/C++ :: Prevent Endless Output Of Sentences?

Nov 16, 2014

After I have compiled and executed code below, and I have made an input of a string, the while loop takes over the control and outputs an endless flow sentences. How can I make sure when an input of string is made, such a thing does not happen? In Python, one can make a type check by the use of type() command, but such a command does not exist in C, so how can I prevent an endless output in case a string input is made by the user?

(The code below is supposed to check whether the number entered by the user is divisible by 7 or not.)

#include <stdio.h>
int main() {
int a = 0;
printf("Input a number!");
while (1 < 2){
scanf("%d", &a);
if (a % 7 == 0) {

[Code] ....

View 3 Replies View Related

C# :: Prevent Sending Multiple Emails

Dec 10, 2014

I have some code which triggers an alarm when an ascii number is read in on the com port:

In that code, i have it send an email to let me know i have an alarm. The problem is it keeps sending the email over and over until i cancel the alarm. Inbox gets full real quick!

Im having trouble implementing a way to send the email just once! Ive googled as much as i can find but i cant get any way to work.

//QT TANK TEMP TOO LOW:
if (ALARM_TYPE_Value == "5") {
ALARM_TYPE_tb.BackColor = Color.Red;
ALARM_TYPE_tb.Text = " **ALARM**" + Environment.NewLine + " ";
ALARM_TYPE_tb.Text += "

[Code] ....

View 4 Replies View Related

C/C++ :: Prevent Duplicate Entry When Insert Age

Oct 17, 2014

I created program that insert employes data and then print their data but never accept duplicate age if user entered duplicated age prompt him to enter another age (age must be unique)

Here is my code

#include<conio.h>
#include<stdio.h>
#define size 3
struct emp {
int age,overtime,dedcution,netsal;

[Code] .....

View 1 Replies View Related

Visual C++ :: Prevent Executable From Running?

Aug 30, 2013

I would like to programmatically monitor a directory for new files, and if the file happens to be an executable, I want to prevent it from running. Something like a AV program.

However, I don't know where to start. Simple is best.

View 9 Replies View Related

Visual C++ :: Prevent DLL From Being Loaded / Injected

Dec 12, 2012

If you're writing a .dll you can prevent that dll from getting loaded into some processes by returning false from the dllmain.

I'm looking for a way to do it the other ay around. I have an exe, and I want to prevent a certain hook dll from getting loaded/injected into my exe.

A customer is running some software which loads a hook dll into our exe, and this is subsequently preventing our application from running as intended. Both our software as well as the third party app is required, and there is no way to get the third party dll changed. (no longer supported).

View 2 Replies View Related

C++ :: Prevent The Loop From Reading The Last File Line Twice?

Oct 19, 2013

I know how to do it in C, but in C++?

Here is my code. Let the variables be of type double.

Code:
while(infile) // Will read the last line twice
{
if(!N)//Read first line of file
{
infile >> d;
infile >> N;
infile >> epsilon;
infile >> t;

[Code] .....

View 8 Replies View Related

C++ :: How To Prevent Someone Passing Classes To Function Template

Sep 13, 2013

Let say i have a following scenario:

a function like this.

Code:
template <typename T1>
print (T1 x){
cout << x << "
";
}

How do I prevent user passing a class or a structure or aanoter function to my function print. I mean i know if a wrong thing is passed that i'll get an error eventually but is there a way to explicitly check what has been passed. How is this done usually ?

View 6 Replies View Related

C :: How To Prevent Fgets From Reading The New Line Character

Mar 12, 2013

i am trying to read a string using fgets and storing in an array i want to prevent fgets from storing the new line character on the array using the shortest means possible..

View 2 Replies View Related

Visual C++ :: How To Prevent A Window From Being Moved Or Resized

May 20, 2014

I know I can set the window properties on creation, but I'm trying to figure out how to prevent a window from being able to be moved or resized. I've been looking online and it looks like it involves overriding the WM_SIZE, WM_SIZING, or perhaps the WM_WINDOWPOSCHANGED message handlers. I want to be able to have a menu option that "locks" the window position, and of course allows normal window behavior when the option isn't checked.

View 1 Replies View Related

C :: Language Program Environment Does Nothing To Prevent Buffer Overflows

Sep 25, 2013

TheC language program environment does nothing to prevent buffer overflows ..... is there any pros to the obvious cons of this?

View 3 Replies View Related

C :: How To Prevent A User From Closing Output Screen During Execution

Sep 17, 2013

I created a C program that extracts some information from computer and displays it on screen. It is completed today and is going to be applied to startup programs of domain machines. It runs at logon and takes somewhat 5-10 seconds to finish execution. The output is shown on console screen & user can either close the window by clicking on 'x' or pressing 'Ctrl+c' during execution. How do i prevent both of these events?

Basically the most time consuming processes are

Code: popen("systeminfo","r");
popen("wmic qfe get installedon","r");

1st command is getting OS name,version and hotfixes installed.
2nd command gives me the date of updates installed.

I then filter out data & print required information only.

View 3 Replies View Related







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