void sim_error(const char msg[]) { clearline(); fred(); printf("ERROR: %s\n", msg); fputc('\n', stdout); fbreset(); exit(-1); }
int main() { fred(); joe(); henry(); return 0; }
bar () { printf ("I am in bar in b.c version %d\n", VERSION); global_var++; fred (); foo (); }
int main() { int i; bill("Hello World"); for(i=0;i<10;i++) fred(i); exit(0); }
bar (int c) /* ERROR: Argument added to function while active on stack */ { c = 5; /* for -gused to emit it */ printf ("I am in bar in b.c version %d\n", VERSION); global_var++; fred (); foo (); }
int main() { int a = 2; int b = 3; //if (a == 2) { // return a; // } //int x; //int y; //int x = bob(fred(a)); //int y = 0; int xp = bob(a); int yp = fred(b); if (xp + yp == 2) { xp = a; } // int x = bob(fred(a)); // int y = fred(bob(b)); return xp + yp; }
// the process code that the host sees static OfxStatus render( OfxImageEffectHandle instance, OfxPropertySetHandle inArgs, OfxPropertySetHandle outArgs) { // get the render window and the time from the inArgs OfxTime time; OfxRectI renderWindow; OfxStatus status = kOfxStatOK; gPropHost->propGetDouble(inArgs, kOfxPropTime, 0, &time); gPropHost->propGetIntN(inArgs, kOfxImageEffectPropRenderWindow, 4, &renderWindow.x1); // retrieve any instance data associated with this effect MyInstanceData *myData = getMyInstanceData(instance); // property handles and members of each image // in reality, we would put this in a struct as the C++ support layer does OfxPropertySetHandle sourceImg = NULL, outputImg = NULL, maskImg = NULL; int srcRowBytes, srcBitDepth, dstRowBytes, dstBitDepth, maskRowBytes, maskBitDepth; bool srcIsAlpha, dstIsAlpha, maskIsAlpha; OfxRectI dstRect, srcRect, maskRect; void *src, *dst, *mask = NULL; try { // get the source image sourceImg = ofxuGetImage(myData->sourceClip, time, srcRowBytes, srcBitDepth, srcIsAlpha, srcRect, src); if(sourceImg == NULL) throw OfxuNoImageException(); // get the output image outputImg = ofxuGetImage(myData->outputClip, time, dstRowBytes, dstBitDepth, dstIsAlpha, dstRect, dst); if(outputImg == NULL) throw OfxuNoImageException(); if(myData->isGeneralEffect) { // is the mask connected? if(ofxuIsClipConnected(instance, "Mask")) { maskImg = ofxuGetImage(myData->maskClip, time, maskRowBytes, maskBitDepth, maskIsAlpha, maskRect, mask); if(maskImg != NULL) { // and see that it is a single component if(!maskIsAlpha || maskBitDepth != srcBitDepth) { throw OfxuStatusException(kOfxStatErrImageFormat); } } } } // see if they have the same depths and bytes and all if(srcBitDepth != dstBitDepth || srcIsAlpha != dstIsAlpha) { throw OfxuStatusException(kOfxStatErrImageFormat); } // are we compenent scaling bool scaleComponents; gParamHost->paramGetValueAtTime(myData->perComponentScaleParam, time, &scaleComponents); // get the scale parameters double scale, rScale = 1, gScale = 1, bScale = 1, aScale = 1; gParamHost->paramGetValueAtTime(myData->scaleParam, time, &scale); if(scaleComponents) { gParamHost->paramGetValueAtTime(myData->scaleRParam, time, &rScale); gParamHost->paramGetValueAtTime(myData->scaleGParam, time, &gScale); gParamHost->paramGetValueAtTime(myData->scaleBParam, time, &bScale); gParamHost->paramGetValueAtTime(myData->scaleAParam, time, &aScale); } rScale *= scale; gScale *= scale; bScale *= scale; aScale *= scale; // do the rendering if(!dstIsAlpha) { switch(dstBitDepth) { case 8 : { ProcessRGBA<OfxRGBAColourB, unsigned char, 255, 0> fred(instance, rScale, gScale, bScale, aScale, src, srcRect, srcRowBytes, dst, dstRect, dstRowBytes, mask, maskRect, maskRowBytes, renderWindow); fred.process(); } break; case 16 : { ProcessRGBA<OfxRGBAColourS, unsigned short, 65535, 0> fred(instance, rScale, gScale, bScale, aScale, src, srcRect, srcRowBytes, dst, dstRect, dstRowBytes, mask, maskRect, maskRowBytes, renderWindow); fred.process(); } break; case 32 : { ProcessRGBA<OfxRGBAColourF, float, 1, 1> fred(instance, rScale, gScale, bScale, aScale, src, srcRect, srcRowBytes, dst, dstRect, dstRowBytes, mask, maskRect, maskRowBytes, renderWindow); fred.process(); break; } } } else { switch(dstBitDepth) { case 8 : { ProcessAlpha<unsigned char, unsigned char, 255, 0> fred(instance, scale, src, srcRect, srcRowBytes, dst, dstRect, dstRowBytes, mask, maskRect, maskRowBytes, renderWindow); fred.process(); } break; case 16 : { ProcessAlpha<unsigned short, unsigned short, 65535, 0> fred(instance, scale, src, srcRect, srcRowBytes, dst, dstRect, dstRowBytes, mask, maskRect, maskRowBytes, renderWindow); fred.process(); } break; case 32 : { ProcessAlpha<float, float, 1, 1> fred(instance, scale, src, srcRect, srcRowBytes, dst, dstRect, dstRowBytes, mask, maskRect, maskRowBytes, renderWindow); fred.process(); } break; } } } catch(OfxuNoImageException &ex) { // if we were interrupted, the failed fetch is fine, just return kOfxStatOK // otherwise, something wierd happened if(!gEffectHost->abort(instance)) { status = kOfxStatFailed; } } catch(OfxuStatusException &ex) { status = ex.status(); } // release the data pointers if(maskImg) gEffectHost->clipReleaseImage(maskImg); if(sourceImg) gEffectHost->clipReleaseImage(sourceImg); if(outputImg) gEffectHost->clipReleaseImage(outputImg); return status; }
baz () { puts ("I am baz."); fred (); }
SymmElasticityTensor SymmElasticityTensor::operator*(Real x) const { SymmElasticityTensor fred(*this); fred *= x; return fred; }
int main() { bill("Hello niuniu "); fred(20); exit(0); }
int main() { std::vector<Person> v1; v1.push_back("Fred"); v1.push_back("Wilma"); v1.push_back("Barney"); v1.push_back("Betty"); const std::vector<Person> cv1(v1.begin(), v1.end()); std::vector<std::string> v2; v2.push_back("Fred"); v2.push_back("Wilma"); v2.push_back("Barney"); v2.push_back("Betty"); Person person; Person &r = person; Person fred("Fred"); Person wilma("Wilma"); Person barney("Barney"); Person betty("Betty"); std::vector<Person*> v3; v3.push_back(&fred); v3.push_back(&wilma); v3.push_back(&barney); v3.push_back(&betty); const std::vector<Person*> cv3(v3.begin(), v3.end()); std::vector<const Person*> v3c(v3.begin(), v3.end()); std::ostream &os = std::cout; #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(__ICL) // unary_traits, unary_negate std::transform(v2.begin(), v2.end(), std::ostream_iterator<bool>(std::cout, " "), boost::not1(is_betty)); std::cout << '\n'; std::transform(v1.begin(), v1.end(), std::ostream_iterator<bool>(std::cout, " "), boost::not1(boost::mem_fun_ref(&Person::is_fred))); // binary_traits, binary_negate std::cout << '\n'; std::transform(v2.begin(), v2.end(), std::ostream_iterator<bool>(std::cout, " "), boost::bind1st(boost::not2(is_equal), "Betty")); std::cout << '\n'; std::transform(v2.begin(), v2.end(), std::ostream_iterator<bool>(std::cout, " "), boost::bind2nd(boost::not2(is_equal), "Betty")); // pointer_to_unary_function std::cout << '\n'; std::transform(v2.begin(), v2.end(), std::ostream_iterator<bool>(std::cout, " "), boost::not1(boost::ptr_fun(is_betty))); // binary_traits, bind1st, bind2nd std::cout << '\n'; std::transform(v2.begin(), v2.end(), std::ostream_iterator<bool>(std::cout, " "), boost::bind1st(is_equal, "Betty")); std::cout << '\n'; std::transform(v2.begin(), v2.end(), std::ostream_iterator<bool>(std::cout, " "), boost::bind2nd(is_equal, "Betty")); // pointer_to_binary_function, bind1st std::cout << '\n'; std::for_each(v2.begin(), v2.end(), boost::bind1st(boost::ptr_fun(do_set_name), &person)); std::cout << '\n'; std::for_each(v2.begin(), v2.end(), boost::bind1st(boost::ptr_fun(do_set_name_ref), person)); std::cout << '\n'; std::for_each(v2.begin(), v2.end(), boost::bind1st(boost::ptr_fun(do_set_name_ref), r)); // binary_traits std::cout << '\n'; std::for_each(v2.begin(), v2.end(), boost::bind1st(do_set_name, &person)); std::cout << '\n'; std::for_each(v2.begin(), v2.end(), boost::bind1st(do_set_name_ref, person)); std::cout << '\n'; std::for_each(v2.begin(), v2.end(), boost::bind1st(do_set_name_ref, r)); #endif // const_mem_fun_t std::cout << '\n'; std::transform(v3.begin(), v3.end(), std::ostream_iterator<std::string>(std::cout, " "), boost::mem_fun(&Person::get_name)); std::cout << '\n'; std::transform(cv3.begin(), cv3.end(), std::ostream_iterator<std::string>(std::cout, " "), boost::mem_fun(&Person::get_name)); std::cout << '\n'; std::transform(v3c.begin(), v3c.end(), std::ostream_iterator<std::string>(std::cout, " "), boost::mem_fun(&Person::get_name)); // const_mem_fun_ref_t std::cout << '\n'; std::transform(v1.begin(), v1.end(), std::ostream_iterator<std::string>(std::cout, " "), boost::mem_fun_ref(&Person::get_name)); std::cout << '\n'; std::transform(cv1.begin(), cv1.end(), std::ostream_iterator<std::string>(std::cout, " "), boost::mem_fun_ref(&Person::get_name)); #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION // const_mem_fun1_t, bind2nd std::cout << '\n'; std::for_each(v3.begin(), v3.end(), boost::bind2nd(boost::mem_fun(&Person::print), std::cout)); std::cout << '\n'; std::for_each(v3.begin(), v3.end(), boost::bind2nd(boost::mem_fun(&Person::print), os)); // const_mem_fun1_ref_t, bind2nd std::cout << '\n'; std::for_each(v1.begin(), v1.end(), boost::bind2nd(boost::mem_fun_ref(&Person::print), std::cout)); std::cout << '\n'; std::for_each(v1.begin(), v1.end(), boost::bind2nd(boost::mem_fun_ref(&Person::print), os)); // mem_fun1_t, bind1st std::cout << '\n'; std::for_each(v2.begin(), v2.end(), boost::bind1st(boost::mem_fun(&Person::set_name), &person)); // mem_fun1_ref_t, bind1st std::cout << '\n'; std::for_each(v2.begin(), v2.end(), boost::bind1st(boost::mem_fun_ref(&Person::set_name), person)); std::cout << '\n'; std::for_each(v2.begin(), v2.end(), boost::bind1st(boost::mem_fun_ref(&Person::set_name), r)); #endif // mem_fun_t std::cout << '\n'; std::transform(v3.begin(), v3.end(), std::ostream_iterator<std::string>(std::cout, " "), boost::mem_fun(&Person::clear_name)); // mem_fun_ref_t std::cout << '\n'; std::transform(v1.begin(), v1.end(), std::ostream_iterator<std::string>(std::cout, " "), boost::mem_fun_ref(&Person::clear_name)); std::cout << '\n'; return 0; }
void main(String args[]) { Student someone; someone.Display(); Student fred(String("Fred"), 4570, String("03/15/1985"), 'M'); fred.Display(); }
int main(){ bill("hello world"); fred(111); exit(0); }
int main() { std::cout << "start of main" << std::endl; // ==================================================== // SINGLE OWNER SMART POINTERS // ==================================================== // first, without smart pointers! Balloon* alice(new Balloon("Hello Kitty")); // now, with our homemade single owner smart pointer dsAutoPtr<Balloon> bob(new Balloon("Spiderman")); // both alice & bob work like regular pointers... alice->print(); bob->print(); // // CHECKPOINT 2A: INSERT NECESSARY EXPLICIT DEALLOCATION // delete alice; // ==================================================== // SIMPLE SHARED POINTERS // ==================================================== // first, without smart pointers Balloon* cathy(new Balloon("Buzz Lightyear")); Balloon* daniel(cathy); Balloon* elaine(new Balloon("Pokemon")); Balloon* fred(elaine); daniel = fred; fred = NULL; elaine = cathy; cathy = NULL; // // CHECKPOINT 2B: INSERT NECESSARY EXPLICIT DEALLOCATION // delete elaine; delete daniel; daniel = NULL; elaine = NULL; // now, with our homemade shared pointer dsSharedPtr<Balloon> cathy2(new Balloon("Buzz Lightyear2")); dsSharedPtr<Balloon> daniel2(cathy2); dsSharedPtr<Balloon> elaine2(new Balloon("Pokemon2")); dsSharedPtr<Balloon> fred2(elaine2); daniel2 = fred2; fred2 = NULL; elaine2 = cathy2; cathy2 = NULL; // NOTE: no explicit destruction required! daniel2 = NULL; elaine2 = NULL; // ==================================================== // SHARED POINTERS WITH INTERCONNECTED STRUCTURES // ==================================================== dsSharedPtr<Balloon> georgette(new Balloon("Mr Potato Head")); dsSharedPtr<Balloon> henry(new Balloon("Snoopy")); georgette->addRope2(henry); henry = new Balloon("Tigger"); georgette->addRope2(henry); georgette->print2(); henry->print2(); dsSharedPtr<Balloon> isabelle(new Balloon("Shrek")); henry->addRope2(isabelle); isabelle = new Balloon("Barney the Purple Dinosaur"); georgette->addRope2(isabelle); henry->print2(); georgette->print2(); isabelle->print2(); // // CHECKPOINT 2C: REWRITE THE ABOVE EXAMPLE TO USE SHARED POINTERS // // ==================================================== // CYCLIC STRUCTURES // ==================================================== // FOR CHECKPOINT 3 Balloon* jacob(new Balloon("Dora the Explorer")); Balloon* katherine(new Balloon("Kung Fu Panda")); Balloon* larry(new Balloon("Scooby Doo")); Balloon* miranda(new Balloon("SpongeBob SquarePants")); Balloon* nicole(new Balloon("Papa Smurf")); jacob->addRope(katherine); katherine->addRope(larry); larry->addRope(jacob); miranda->addRope(jacob); nicole->addRope(miranda); larry->addRope(nicole); katherine = NULL; larry = NULL; miranda = NULL; nicole = NULL; // jacob points to a cyclic structure! // to cleanup this structure: deleteAll(jacob); //delete jacob; jacob = NULL; std::cout << "end of main" << std::endl; return 0; // // NOTE: when smart pointers go out of scope, the destructors for // those objects will be called automatically // }
TEST_CASE test_concurrent_list() { stdString fred("fred"); stdString freddy("freddy"); stdString jane("jane"); stdString janet("janet"); stdString bob("bob"); ConcurrentList<stdString> subscribers; TEST(subscribers.isEmpty() == true); TEST(subscribers.size() == 0); TEST(subscribers.removeIfFound(&bob) == false); subscribers.add(&fred); TEST(subscribers.isEmpty() == false); TEST(subscribers.size() == 1); subscribers.add(&freddy); TEST(subscribers.isEmpty() == false); TEST(subscribers.size() == 2); subscribers.add(&jane); TEST(subscribers.isEmpty() == false); TEST(subscribers.size() == 3); subscribers.add(&janet); TEST(subscribers.isEmpty() == false); TEST(subscribers.size() == 4); TEST(subscribers.removeIfFound(&bob) == false); // This test assumes a certain order in which // elements are added to the list, // which could change with different implementations // of the ConcurrentList. COMMENT("Simple Iteration"); ConcurrentListIterator<stdString> s(subscribers.iterator()); TEST(*s.next() == "fred"); TEST(*s.next() == "freddy"); TEST(*s.next() == "jane"); TEST(*s.next() == "janet"); TEST(s.next() == 0); TEST(s.next() == 0); TEST(s.next() == 0); TEST(s.next() == 0); COMMENT("Iteration where 'fred' is removed while iterator is on it"); // Start over: Position on first entry, "fred" s = subscribers.iterator(); // Remove element, ... subscribers.remove(&fred); // but iterator was already on the element, so you still get it: TEST(*s.next() == "fred"); TEST(*s.next() == "freddy"); TEST(*s.next() == "jane"); TEST(*s.next() == "janet"); TEST(s.next() == 0); TEST(s.next() == 0); COMMENT("Iteration where 'fred' is gone, but 'bob' was added."); COMMENT("Then add 'fred' again while iterating."); subscribers.add(&bob); s = subscribers.iterator(); TEST(*s.next() == "bob"); TEST(*s.next() == "freddy"); subscribers.add(&fred); TEST(*s.next() == "jane"); TEST(*s.next() == "janet"); TEST(*s.next() == "fred"); TEST(s.next() == 0); TEST(s.next() == 0); TEST_OK; }
void X::f( int x = fred( 0) ) { // { dg-error "default argument" } }
int main() { fred("Hellow World"); return 0; }
void X::f( int x = fred( 0) ) {// ERROR - .* }