Questions tagged [c]

575028 questions
3

votes
2

answer
226

Views

Block concurrent access ThreadPool

So I'm running a query and processing the rows that return concurrently using a function called StartJob that will work on my job: ThreadPool.QueueUserWorkItem(StartJob, job); Works great and is very fast. But now I'm told that when the query returns, some rows may have the same value for job.UserID...
powlette
4

votes
2

answer
213

Views

How to use operator= with anonymous objects in C++?

I have a class with an overloaded operator: IPAddress& IPAddress::operator=(IPAddress &other) { if (this != &other) { delete data; this->init(other.getVersion()); other.toArray(this->data); } return *this; } When I try to compile this: IPAddress x; x = IPAddress(IPV4, '192.168.2.10'); I get the foll...
Allan
2

votes
3

answer
218

Views

Is there a point at which an Enum can get too bloated?

I've defined an Enum as part of the model objects for an ASP.NET MVC application. The Enum is called 'ContentTypes' and looks something like this: public enum ContentTypes { [Description('News story')] NewsStory = 1, [Description('Article')] Article = 2 } Now I'm planning to add another set of attri...
Jonathan
2

votes
3

answer
275

Views

Good, secure encryption

Hi im thinking about developing a sort of File Transfer program and was wondering if i want as good encryption that i can get what should i use? ill be developing this with c# so i got access to the .net lib :P having a certificate with me on my usb to access the server is no problem if that would i...
Peter
3

votes
1

answer
174

Views

Repeatable logic for variety of objects

So here is the code: return new DistrictInfo { rid = Convert.ToUInt32(((OracleNumber)o.GetOracleValue('rid')).Value), doc = Convert.ToUInt16(((OracleNumber)o.GetOracleValue('doctor')).Value), secdoc = Convert.ToUInt16(((OracleNumber)o.GetOracleValue('secdoctor')).Value), num = Convert.ToUInt16((...
kseen
6

votes
3

answer
1.6k

Views

Windows Phone 8.1 XAML App. How to prevent inappropriate automatic focus change?

Imagine the following simple page markup: and the following code-behind: private void ButtonBase_OnClick(object sender, RoutedEventArgs e) { Button1.Visibility = Visibility.Collapsed; } When I click Button1 button it hides (which is expected and desired) but for some reason TextBox automatically get...
proman
11

votes
2

answer
624

Views

How to print a double value that is just less than another double value?

Actually I am working on range expression in c++. So what I want is if I have any expression like x
Apoorva sahay
2

votes
1

answer
113

Views

Processing values from a Thread Executing a yield return Function

I am new to multi threading and I am trying make an enumerator in a way that I receive a value as it is ready, but that it continues to process in the background. I want to be able to use the final class like this: while (await asyncEnumerator.MoveNextAsync()) { T result = asyncEnum.Current; //Do So...
tjw
2

votes
3

answer
441

Views

Is there an easier way to type and compile C on Mac OS X?

I've just started learning C on Mac OS X. I have downloaded Xcode too. So far, I have been typing my apps into TextEdit, and then using the Terminal to locate my apps and compile them using gcc hello.c etc. Is there an easier way (using Xcode perhaps?) to type my code into some form of IDE, and then...
alex
3

votes
2

answer
181

Views

Floyd algorithm - Cycle Detection - not terminating for the example

Can someone please explain Floyd algorithm with this example. It is not terminating for me and is the algorithm implemented complete ?. Is something wrong with my code? Code is as follows: Node* FindLoopBegin(Node *head){ Node *slowptr = head,*fastptr = head; bool LoopExists = false; while(slowptr...
Vishnu
2

votes
1

answer
60

Views

Endianess Related to processor or data type

I am working with little endian processor PIC 32 and am looking at a variable that is of type BOOL. One variable is initialized to TRUE and the other as false. static BOOL A = TRUE; BOOL static B = FALSE; In Memory when I look in memory for variable A, it shows It looks like the processor just assig...
newb7777
3

votes
1

answer
443

Views

Windsor Typed Factory Not Releasing Children

I have a factory and component registered in Windsor 2.5.1 like so: interface IFooFactory{ IFoo CreateFoo(); } interface IFoo { void DoSomething(); } class ConcreteFoo : IFoo, IDisposable { public void Dispose(){ Log.info('Going now, bye!') } } container.Register( Component.For().AsFactory().Lifesty...
amarsuperstar
7

votes
4

answer
999

Views

How to get PHP standard functions in C?

How can I call PHP functions from my C application? Example: include int main() { return json_encode(''); // This is a PHP function coming from php.h } Note: PHP function collections is very managed and organized, i just want to have that logic in my C application, everything organized on-demand. T...
YumYumYum
6

votes
3

answer
77

Views

Memory read visibility ordering vs write order using double-checked locking

I have the following function which is intended to 'memoize' argument-less functions. Meaning to only call the function once, and then return the same result all other times. private static Func Memoize(Func func) { var lockObject = new object(); var value = default(T); var inited = false; return ()...
NotNull
2

votes
1

answer
173

Views

Not-hash-based set collection for storing unique objects with custom equality comparer - C#

I'm trying to store (name: string, value: long) pair in a set. public class NameValuePair { public string name; public long value; } public NameValuePairComparer comparer = new NameValuePairComparer(); public HashSet nameValueSet = new HashSet(comparer); Two pairs are equal if either they have equal...
Mariusz Ceier
3

votes
2

answer
523

Views

(Simple C++ Concepts) Unexpected output of constructor/destructor calls

Given this code: #include using namespace std; class Foo { public: Foo () { c = 'a'; cout
Jason
11

votes
2

answer
471

Views

Shouldn't istream::peek() always return what you just putback()?

Intuitively, judging from the C++ spec, it looks to me as if istream::putback( c ) should always arrange the input buffer such that the next call to istream::peek() should read the character c. Is this not correct? I ask because the latest version of libc++ shipping with Xcode 4.6 seems not to enfor...
OldPeculier
11

votes
1

answer
236

Views

Why does the cast operator to a private base not get used?

In this code assigning to b1 works, but it won't allow assigning to b2 (with or without the static cast). I was actually trying to solve the opposite problem, public inheritance but not implicitly converting to the base. However the cast operator never seems to be used. Why is this? struct B {};...
Barabas
2

votes
4

answer
220

Views

Object initializers and Constructors

I am trying to use Object initializers to set the properties of a class and then access them within the constructor of the class. The problem is that the properties do not seem to be set until after the constructor runs. Am I doing something wrong. Basic Class.. public class TestClass { public stri...
TampaRich
2

votes
5

answer
696

Views

Best way to deal with object that can't instantiate itself?

I guess I've asked a few similar questions before, but I was beating around the bush. I think this is the real problem that I can't quite lay to rest. I'm dealing with a third party library, and there's an object that can't create itself, b2Body. The b2World has to instantiate it. I personally don't...
11

votes
5

answer
1k

Views

Avoid explicit type casting when overriding inherited methods

I have a base abstract class that also implements a particular interface. public interface IMovable where TEntity: class where T: struct { TEntity Move(IMover moverProvider); } public abstract class Animal : IMovable { ... public virtual Animal Move(IMover moverProvider) { // performs movement using...
3

votes
1

answer
931

Views

Does not appear to be emitting correct GridView markup for __doPostBack

I asked this question regarding a strange behaviour from a GridView control in ASP.Net (I'm using C#). For each row in my GridView there is an an 'Edit' and 'Delete' link. The edit for example has this javascript:__doPostBack('gvwServers','Edit$0') - So obviously the server is going to figure out so...
El Ronnoco
3

votes
3

answer
1.6k

Views

Determine whether a C# method has keyword 'override' using Reflection

I had expected to find an answer easily to this problem, but I didn't. I'd like to know if it is possible to determine whether a method has the keyword 'override' attributed to it, given its instance of MethodInfo. I was thinking maybe the following would achieve that: /// Returns whether the speci...
JBSnorro
3

votes
1

answer
446

Views

Linq to twitter error

I'd like to retrieve an user's statuses to display them in a listbox (in a webform). Here is my code : var twitterCtx = new TwitterContext(); var publicTweets = from tweet in twitterCtx.Status where tweet.Type == StatusType.User && tweet.ScreenName == txtName.Text select tweet.Text; _status = public...
2

votes
5

answer
175

Views

Printing like Perl in C++

Can I do something like the following Perl code in C++ ? i.e Replicate $string n times ? printf ('%s\n',$string x 4);
Jean
2

votes
1

answer
135

Views

filter a datatable to contain unique columns

I have a datatable as follows ID(INT NOT NULL AND PK) Name(NOT NULL NVARCHAR) 1 Apple 2 Apple 3 Apple 4 Orange 5 Apple 6 Orange I need to filter th...
Eve
3

votes
4

answer
86

Views

Polymorphic function in class which is implementing abstract class

class Eq { public: virtual bool operator==(Eq operand) = 0; }; class Day : public Eq { public: enum DAY { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday } day; Day(DAY init_day) : day(init_day){} bool operator==(Day operand) { return day == operand.day; } }; int main() { Day d1(Day::...
Mossid
4

votes
2

answer
202

Views

I have a custom expression program with a lexer, parser and evaluator. How do I LINQ-ify it?

Here are my interfaces and enum, dumbed down slightly. : public interface IExpression { ExpressionType ExpressionType { get; } } public interface ILiteralExpression : IExpression { object Value { get; set; } } public interface IOperatorExpression : IExpression { IExpression[] Operands { get; set; }...
5

votes
4

answer
300

Views

C macro argument 'storage'

Given: #define f(x, y) (x+y) #define g(x, y) (x*y) #define A 1, 2 #define B 2, 3 int main() { int a = f(A); int b = g(A); int c = f(B); int d = g(B); } which does not work, how can I make it work? The basic idea is that I have one list of arguments that I want to pass to two different macros, withou...
anon
2

votes
2

answer
112

Views

C# Set of Objects Referenced by Class

What I want is a unique collection, or set, of objects referenced by their class. This set can only contain one object of a given class. Here is an example of some possible functionality: class A; class B; class C; A a = new A(); B b = new B(); C c = new C(); UnknownCollection objects; objects.Add(A...
CuddleBunny
3

votes
4

answer
389

Views

Having issues with initializing character array

Ok, this is for homework about hashtables, but this is the simple stuff I thought I was able to do from earlier classes, and I'm tearing my hair out. The professor is not being responsive enough, so I thought I'd try here. We have a hashtable of stock objects.The stock objects are created like so: s...
quandrum
3

votes
1

answer
145

Views

pre-increment not working as i expect

I am trying to learn dynamic programming by solving some questions online. One question that i came across requires the to process the following input 4 10 3 4 4 5 6 7 5 7 The first points at number of items, second the total capacity and the rest of the four (in a pair) should now point at the va...
Arun Khetarpal
5

votes
2

answer
488

Views

How to take away vertical space for programmatically added menu?

I add a MenuStrip to my form and I would like to add other controls below it like usual Point(0, 0) is the top left corner of empty form space. After I add the menu to my form and add more controls they overlap each other. So I want to take away some height of the client rect for the menu and a butt...
Bitterblue
2

votes
2

answer
226

Views

“throw” crashes program, but compiles fine

My program compiles fine, but crashes everytime throw (not inside of a try...catch block) is called. Here are the command like arguments used for all files in the project: mingw32-g++.exe -fexceptions -DWIN32 -D_WINDOWS -D_MBCS -DNO_SOCKLEN_T -DDONTUSEMEMMANAGER -Wall -g -W -fexceptions -DDEBUG...
just Nik
3

votes
1

answer
339

Views

Troubles with boost::phoenix::function

Using boost::phoenix::function I encountered some problems. As far as I know this lazy function requiries functor as its template parameter. I have to define a functor class/structure and then pass it as a template parameter for instantiation. But it's too long and redundant. Can I use some other ca...
Oleksandr Karaberov
2

votes
3

answer
104

Views

Why do a[] and *a behave differently?

I thought a[] and *a are the same thing because they work like pointers. Yet I encountered something unexpected in the following code: #include using namespace std; class F { public: bool a[]; F(); }; F::F() { *a = new bool[5]; a[2] = true; } int main() { F obj; if(obj.a[2]) cout
Marko Divjak
4

votes
6

answer
136

Views

Simple Way to Read Integers from a File

I am trying to read in a file which is essentially a list of integers, seperated by a line. Obviously, file input can never be trusted so I need to filter out non-integers. 1 2 3 4 I know the as operator usually converts if it can and then assigns a null, however because int isn't nullable this isn'...
LukeHennerley
6

votes
4

answer
577

Views

C#/Linq get sets with adjacent

I have an ordered list like 0,1,2, 6,7, 10 I want to get the sets where the numbers are incremented by 1. I want the first number and the count or the series. So I would get start=0, count=3 start=6, count=2 start=10, count=1 How can I do that in C#? The answer goes to what I feel is the nicest way...
Karsten
3

votes
2

answer
780

Views

File open mode inconsistency between C# and C++

I am exporting a function from vc++ DLL to write to a binary file. In the C++ code the file is opened using FILE* fp = ::_tfopen (FilePath, _T('a+b')); I a using the 'a+b' mode to append the file later on and b is for the binary mode. Now I am importing this function in my C# application. When I ma...
zack
5

votes
4

answer
266

Views

What is the Best Way to Debug a Windows Service program in Visual Studio 2008

I am using the Microsoft Log Parser in a Windows Service. The program works in a regular web page but when I put the code in a windows service it does not work. I put Breakponts in the windows service but when I run the code the program does not stop at the breakpoint. So through out my troubleshoo...
Luke101