How can the below code result in a dangling pointer.
{
char *cPointer = malloc ( some constant number );
/* some code */
free ( cPointer );
cPointer = NULL;
/* some code */
}
We are migrating to Sun Studio 12.1 and with the new compiler [ CC: Sun C++ 5.10 SunOS_sparc 2009/06/03 ]. I am getting compilation error while compiling a code that compiled fine with earlier version of Sun Compiler [ CC: Sun WorkShop 6 update 2 C++ 5.3 2001/05/15 ].
This is the compilation error I get.
"Sample.cc": Error: Could not find a match for LoopThrough(int[2])
needed in main(). 1 Error(s) detected.
* Error code 1.
CODE:
#include <iostream>
#define PRINT_TRACE(STR) \
std::cout << __FILE__ << ":" << __LINE__ << ":" << STR << "\n";
template<size_t SZ>
void LoopThrough(const int(&Item)[SZ])
{
PRINT_TRACE("Specialized version");
for (size_t index = 0; index < SZ; ++index)
{
std::cout << Item[index] << "\n";
}
}
/*
template<typename Type, size_t SZ>
void LoopThrough(const Type(&Item)[SZ])
{
PRINT_TRACE("Generic version");
}
*/
int main()
{
{
int arr[] = { 1, 2 };
LoopThrough(arr);
}
}
If I uncomment the code with Generic version, the code compiles fine and the generic version is called. I don't see this problem with MSVC 2010 with extensions disabled and the same case with ideone here.
The specialized version of the function is called. Now the question is, is this a bug in Sun Compiler ?
If yes, how could we file a bug report ?
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
My code get this event more than once while device is rotating. I'm searching in apple docs for reference but seems no lucky. Could any one offer a hint why this is happening?
My code is an apple doc sample code, without any change but some logs.
http://developer.apple.com/iphone/library/samplecode/AlternateViews/Introduction/Intro.html#//apple_ref/doc/uid/DTS40008755
NOTE: This question is written in a C# like pseudo code, but I am really going to ask which languages have a solution. Please don't get hung up on syntax.
Say I have two classes:
class AngleLabel: CustomLabel
{
public bool Bold;
// code to allow the label to be on an angle
}
class Label: CustomLabel
{
public bool Bold;
// Code for a normal label
// Maybe has code not in an AngleLabel (align for example).
}
They both decend from this class:
class CustomLabel: Control
{
protected bool Bold;
}
The bold field is exposed as public in the descended classes.
No interfaces are available on the classes.
Now, I have a method that I want to beable to pass in a CustomLabel and set the Bold property. Can this be done without having to 1) find out what the real class of the object is and 2) cast to that object and then 3) make seperate code for each variable of each label type to set bold. Kind of like this:
public void SetBold(customLabel: CustomLabel)
{
AngleLabel angleLabel;
NormalLabel normalLabel;
if (angleLabel is AngleLabel )
{
angleLabel= customLabel as AngleLabel
angleLabel.Bold = true;
}
if (label is Label)
{
normalLabel = customLabel as Label
normalLabel .Bold = true;
}
}
It would be nice to maybe make one cast and and then set bold on one variable.
What I was musing about was to make a fourth class that just exposes the bold variable and cast my custom label to that class.
Would that work?
If so, which languages would it work for? (This example is drawn from an old version of Delphi (Delphi 5)). I don't know if it would work for that language, (I still need to try it out) but I am curious if it would work for C++, C# or Java.
If not, any ideas on what would work? (Remember no interfaces are provided and I can not modify the classes.)
Any one have a guess?
Hello,
I have a data frame in R with the following structure.
> testData
date exch.code comm.code oi
1 1997-12-30 CBT 1 468710
2 1997-12-23 CBT 1 457165
3 1997-12-19 CBT 1 461520
4 1997-12-16 CBT 1 444190
5 1997-12-09 CBT 1 446190
6 1997-12-02 CBT 1 443085
....
77827 2004-10-26 NYME 967 10038
77828 2004-10-19 NYME 967 9910
77829 2004-10-12 NYME 967 10195
77830 2004-09-28 NYME 967 9970
77831 2004-08-31 NYME 967 9155
77832 2004-08-24 NYME 967 8655
What I want to do is produce a table the shows for a given date and commodity the total oi across every exchange code. So, the rows would be made up of
unique(testData$date)
and the columns would be
unique(testData$comm.code)
and each cell would be the total oi over all exch.codes on a given day.
Thanks,
Hi.
Tumblr and other blogging websites allows people to post embeded codes of videos from youtube and all video networks.
but how they filter only the flash object code and remove any other html or scripts? and even they have an automated code that informes you this is not a valid video code.
Is this done using REGEX expressions? And Is there a PHP class to do that?
Thanks
What is a machine learning ?
What does machine learning code do ?
When we say machine learns, does it modify the code of itself or it modifies history(Data Base) which will contain the experience of code for given set of inputs ?
im trying to work through some questions and im not sure how to do the following
Q:Find the hard drive sizes that are equal among two or more PCs.
its q15 on this site
http://www.sql-ex.ru/learn_exercises.php#answer_ref
The database scheme consists of four tables:
Product(maker, model, type)
PC(code, model, speed, ram, hd, cd, price)
Laptop(code, model, speed, ram, hd, screen, price)
Printer(code, model, color, type, price)
any pointers would be appreciated.
Hi Y'all.
I'd like to statistically profile my C code at the instruction level.
I need to know how many additions, multiplications, devides, etc,... I'm performing.
This is not your usual run of the mill code profiling requirement. I'm an algorithm developer and I want to estimate the cost of converting my code to hardware implementations. For this, I'm being asked the instruction call breakdown during run-time (parsing the compiled assembly isn't sufficient as it doesn't consider loops in the code).
After looking around, It seems VMWare may offer a possible solution, but I still couldn't find the specific feature that will allow me to trace the instruction call stream of my process.
Are you aware of any profiling tools which enable this?
Hi, I am planning to participate in development of a code written in C language for Monte Carlo analysis of complex problems. This codes allocates huge data arrays in memory to speed up its performance, therefore the author of the code has chosen C instead of C++ claiming that one can make faster and more reliable (concerning memory leaks) code with C.
Do you agree with that? What would be your choice, if you need to store 4-16 Gb of data arrays in memory during calculation?
I know it's important to keep user interface code separated from domain code--the application is easier to understand, maintain, change, and (sometimes) isolate bugs. But here's my mental block ...
Delphi comes with components with methods that do what I want, e.g., a RichText Memo component lets me work with rich text. Other components, like TMS's string grid not only do what I want, but I paid extra for the functionality. These features put the R in RAD.
It seems illogical to write my own classes to do things somebody else has already done for me. It's reinventing the wheel [ever tried working directly with rich text? :-) ] But if I use the functionality built into components like these, then I will end up with lots of intermingled UI and domain code--I'll have a form with most of my code built into its event handlers.
How do you deal with this issue? ... Or, if I want to continue using the code others have already written for me, how would you suggest I deal with the issue?
I was just wondering, what could possibly be the largest amout of code possible to write a Hello, World! program, without repeating code, without any whitespace, as few newlines as possible, whitout code that doesn't need to be there, and not written in 'Shakespeare'?
Programming language doesn't matter ^^
I am using below code for javascript window "Yes/No". It is firing twice. Is there any way I can avoid this? Or use any other code?. I need this code behind.
Response.Write("<script language='javascript'> { self.close() }</script>");
Very very weird problem with UIImageView property on iPad application
@interface MyViewController : UIViewController {
IBOutlet UIImageView* coverImage;
}
@property(nonatomic, retain) IBOutlet UIImageView* coverImage;
… more code
@implementation MyViewController
@synthesize coverImage;
… more code
- (void)viewDidLoad {
[super viewDidLoad];
NSString* imageName = @"my_image.png";
UIImage* tempImage = [UIImage imageNamed:imageName];
[self.coverImage setImage:tempImage];
}
The above code WILL display the image.
In another part of code:
-(IBAction) stopButtonPressed:(id)sender {
[self.coverImage setHidden:YES];
NSLog(@"coverImage desc: %@", [coverImage description]);
}
The image will NOT disappear. I know the reference to the image isn't nil, because it gives me this output:
2010-05-29 17:37:40.706 MyApp[95360:207] coverImage desc: UIImageView: 0x5128420; frame = (0 0; 1024 768); autoresize = RM+BM; userInteractionEnabled = NO; layer = CALayer: 0x512bed0
In addition, if I move the code in viewDidLoad to another part of the class, and try to execute it from there, it fails to show the image at all.
I need some help to understand how this code was obfuscated. The code is:
<a id="suggest" href="#" ajaxify="/ajax/social_graph/invite_dialog.php?class=FanManager&node_id=108463912505356" class=" profile_action actionspro_a" rel="dialog-post">Suggest to Friends</a>
And the obfuscation is:
\x3c\x61\x20\x69\x64\x3d\x22\x73\x75\x67\x67\x65\x73\x74\x22\x20\x68\x72\x65\x66\x3d\x22\x23\x22\x20\x61\x6a\x61\x78\x69\x66\x79\x3d\x22\x2f\x61\x6a\x61\x78\x2f\x73\x6f\x63\x69\x61\x6c\x5f\x67\x72\x61\x70\x68\x2f\x69\x6e\x76\x69\x74\x65\x5f\x64\x69\x61\x6c\x6f\x67\x2e\x70\x68\x70\x3f\x63\x6c\x61\x73\x73\x3d\x46\x61\x6e\x4d\x61\x6e\x61\x67\x65\x72\x26\x61\x6d\x70\x3b\x6e\x6f\x64\x65\x5f\x69\x64\x3d\x31\x30\x38\x34\x36\x33\x39\x31\x32\x35\x30\x35\x33\x35\x36\x22\x20\x63\x6c\x61\x73\x73\x3d\x22\x20\x70\x72\x6f\x66\x69\x6c\x65\x5f\x61\x63\x74\x69\x6f\x6e\x20\x61\x63\x74\x69\x6f\x6e\x73\x70\x72\x6f\x5f\x61\x22\x20\x72\x65\x6c\x3d\x22\x64\x69\x61\x6c\x6f\x67\x2d\x70\x6f\x73\x74\x22\x3e\x53\x75\x67\x67\x65\x73\x74\x20\x74\x6f\x20\x46\x72\x69\x65\x6e\x64\x73\x3c\x2f\x61\x3e","\x73\x75\x67\x67\x65\x73\x74
Now I used unescape on the above obfuscated code to read it. What I want to know is what exactly was used to obfuscate the code like that? Basically, I need to customize the readable code to the same obfuscation.
Any help would be greatly appreciated.
I'm trying to get my Javascript code 100% JSLint clean.
I've got some JS code that I've lifted from elsewhere to create a UUID. That code has the following line:
s[16] = hexDigits.substr((s[16] & 0x3) | 0x8, 1);
This line incites JSLint to generate two error messages:
1) Unexpected use of '&'
2) Unexpected use of '|'
I don't understand why -- I'd appreciate counsel regarding how to recode to eliminate the error message.
[Edit: see below for final code] I have the following code and I'm trying to figure out where to insert the random.choice code to make it select a single file, copy it, and repeat (here 6 times).
import os
import shutil
import random
dir_input = str(input("Enter Source Directory: "))
src_files = (os.listdir(dir_input))
for x in range (0,5):
print ('This is the %d time' % x)
for file_name in src_files:
full_file_name = (os.path.join(dir_input, file_name))
if (os.path.isfile(full_file_name)):
print ('copying...' + full_file_name)
shutil.copy(full_file_name, r'C:\Dir'))
else:
print ('Finished!')
I have the following code:
public bool ProcessData(String data)
{
try
{
result= CheckData(data);
if (TextUtils.isEmpty(result))
{
summary="Data is invalid";
return false;
}
...
finally
{
Period period = new Period(startTime, new LocalDateTime());
String duration = String.format("Duration: %s:%s",
period.getMinutes(), period.getSeconds());
LogCat(duration);
}
return true;
As I learned from this question, the finally block is executed after the return statement. So I modified my code according to that, and in the finally I inserted code that does not modify the output.
Strangely, the code OUTSIDE the finally block does.
My method always returns true.
As suggested, it is not a good idea to have 2 return.
What should I do?
When it comes to coding style I'm a pretty relaxed programmer. I'm not firmly dug into a particular coding style. I'd prefer a consistent overall style in a large code base but I'm not going to sweat every little detail of how the code is formatted.
Still there are some coding styles that drive me crazy. No matter what I can't look at examples of these styles without reaching for a VIM buffer to "fix" the "problem". I can't help it. It's not even wrong, I just can't look at it for some reason.
For instance the following comment style almost completely prevents me from actually being able to read the code.
if (someConditional)
// Comment goes here
{
other code
}
What's the most frustrating style you've encountered?
I'd like to learn other people workflow when using either SVN or GIT.
Please describe your strategy to handle the following tasks:
Implement a feature
Fixing bugs (during development and deployed app)
Code Review
Refactoring code (post code-review)
Incorporate patches
Releasing the newer version of your app (desktop, web, mobile, would you treat them differently?)
Feel free to organize your answer not grouped by the tasks but grouped by whatever you think is relevant but please organize it by VCS/DVCS (please don't mix them).
Thank you.
I want to know about the name of all currently opened MS-Word file by its unique id.
I found unique id for one file but when I gave its destination path in code.
My requirement is that when any user open Word file then the unique id of this file is passed into my code and through this code the name of this file is stored into database (but it is done backgroundly and for multiple files).
Hello,
I am trying to compile the Enet source code into my code framework for iPhone games. After modifying the header files I get it compiling and linking, but I absolutely must be compiling with the "Compile Source As" set to "Objective-C++" in my xcode project (because the framework code requires this). When I flip this switch in my test project, I get these errors:
Undefined symbols:
"_enet_list_clear", referenced from:
_enet_host_connect in host.o
...
Can anyone help get this linking with "Compile Source As" set to "Objective-C++"?
I'm writing some terrible, terrible code, and I need a way to put a free() in the middle of a statement. The actual code is:
int main(){
return printf("%s", isPalindrome(fgets(malloc(1000), 1000, stdin))?"Yes!\n":"No!\n") >= 0;
// leak 1000 bytes of memory
}
I was using alloca(), but I can't be sure that will actually work on my target computer. My problem is that free returns void, so my code has this error message:
error: void value not ignored as it ought to be
The obvious idea I had was:
int myfree(char *p){
free(p);
return 0;
}
Which is nice in that it makes the code even more unreadable, but I'd prefer not to add another function.
I also briefly tried treating free() as a function pointer, but I don't know if that would work, and I don't know enough about C to do it properly.
Note: I know this is a terrible idea. Don't try this at home kids.
I am using below formula to move the ball circular, where accelX and accelY are the values from accelerometer, it is working fine.
But the problem in this code is mRadius (I fixed its value to 50), i need to change mRadius according to accelerometer values and also i need bouncing effect when it touches the track. Currently i am developing code by assuming only one ball is on the board.
float degrees = -atan2(accelX, accelY) * 180 / 3.14159;
int x = cCentrePoint.x + mRadius * cos(degreesToRadians(degrees));
int y = cCentrePoint.y + mRadius * sin(degreesToRadians(degrees));
Here is the snap of the game i want to develop:
Updated: I am sending the updated code...
mRadius = 5;
mRange = NSMakeRange(0,60);
-(void) updateBall: (UIAccelerationValue) accelX withY:(UIAccelerationValue)accelY
{
float degrees = -atan2(accelX, accelY) * 180 / 3.14159;
int x = cCentrePoint.x + mRadius * cos(degreesToRadians(degrees));
int y = cCentrePoint.y + mRadius * sin(degreesToRadians(degrees));
//self.targetRect is rect of ball Object
self.targetRect = CGRectMake(newX, newY, 8, 9);
self.currentRect = self.targetRect;
//http://books.google.co.in/books?id=WV9glgdrrrUC&pg=PA455#v=onepage&q=&f=false
static NSDate *lastDrawTime;
if(lastDrawTime!=nil)
{
NSTimeInterval secondsSinceLastDraw = -([lastDrawTime timeIntervalSinceNow]);
ballXVelocity = ballXVelocity + (accelX * secondsSinceLastDraw) * [self isTouchedTrack:mRadius andRange:mRange];
ballYVelocity = ballYVelocity + -(accelY * secondsSinceLastDraw) * [self isTouchedTrack:mRadius andRange:mRange];
distXTravelled = distXTravelled + secondsSinceLastDraw * ballXVelocity * 50;
distYTravelled = distYTravelled + secondsSinceLastDraw * ballYVelocity * 50;
CGRect temp = self.targetRect;
temp.origin.x += distXTravelled;
temp.origin.y += distYTravelled;
int radius = (temp.origin.x - cCentrePoint.x) / cos(degreesToRadians(degrees));
if( !NSLocationInRange(abs(radius),mRange))
{
//Colided with the tracks...Need a better logic here
ballXVelocity = -ballXVelocity;
}
else
{
// Need a better logic here
self.targetRect = temp;
}
//NSLog(@"angle = %f",degrees);
}
[lastDrawTime release];
lastDrawTime = [ [NSDate alloc] init];
}
In the above code i have initialized mRadius and mRange(indicate track) to some constant for testing, i am not getting the moving of the ball as i expected( bouncing effect when Collided with track ) with respect to accelerometer. Help me to recognize where i went wrong or send some code snippets or links which does the similar job.
I am searching for better logic than my code, if you found share with me.
I'm working with VS2005, and SSMS 2005.
SQL Server allows nested comments as follows:
/* Comment 1
/* Comment 2 */
Some commented out code here
*/
This code runs fine. However if putting the above into a .sql file in VS2005, it incorrectly shows the commented out code as 'active', (its not green). It seems that StackOverflow has highlighted the code in the same way.
Is this a bug in VS2005? Or does SSMS handle nested comments differently compared to the ANSI SQL standards?
Can someone clarify this discrepancy, and if it appears to be a bug, if there a way to fix the syntax highlighting?