Search Results

Search found 9082 results on 364 pages for 'c functions'.

Page 17/364 | < Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >

  • pointers to functions

    - by DevAno1
    I have two basic Cpp tasks, but still I have problems with them. First is to write functions mul1,div1,sub1,sum1, taking ints as arguments and returning ints. Then I need to create pointers ptrFun1 and ptrFun2 to functions mul1 and sum1, and print results of using them. Problem starts with defining those pointers. I thought I was doing it right, but devcpp gives me errors in compilation. #include <iostream> using namespace std; int mul1(int a,int b) { return a * b; } int div1(int a,int b) { return a / b; } int sum1(int a,int b) { return a + b; } int sub1(int a,int b) { return a - b; } int main() { int a=1; int b=5; cout << mul1(a,b) << endl; cout << div1(a,b) << endl; cout << sum1(a,b) << endl; cout << sub1(a,b) << endl; int *funPtr1(int, int); int *funPtr2(int, int); funPtr1 = sum1; funPtr2 = mul1; cout << funPtr1(a,b) << endl; cout << funPtr2(a,b) << endl; system("PAUSE"); return 0; } 38 assignment of function int* funPtr1(int, int)' 38 cannot convertint ()(int, int)' to `int*()(int, int)' in assignment Task 2 is to create array of pointers to those functions named tabFunPtr. How to do that ?

    Read the article

  • Reducing Code Repetition: Calling functions with slightly different signatures

    - by Brian
    Suppose I have two functions which look like this: public static void myFunction1(int a, int b, int c, string d) { //dostuff someoneelsesfunction(c,d); //dostuff2 } public static void myFunction2(int a, int b, int c, Stream d) { //dostuff someoneelsesfunction(c,d); //dostuff2 } What would be a good way to avoid repeated dostuff? Ideas I've thought of, but don't like: I could make d an object and cast at runtype based on type, but this strikes me as not being ideal; it removes a type check which was previously happening at compile time. I could also write a private helper class that takes an object and write both signatures as public functions. I could replace dostuff and dostuff2 with delegates or function calls or something.

    Read the article

  • Compiled Linq Queries with Built-in SQL functions

    - by Brandi
    I have a query that I am executing in C# that is taking way too much time: string Query = "SELECT COUNT(HISTORYID) FROM HISTORY WHERE YEAR(CREATEDATE) = YEAR(GETDATE()) "; Query += "AND MONTH(CREATEDATE) = MONTH(GETDATE()) AND DAY(CREATEDATE) = DAY(GETDATE()) AND USERID = '" + EmployeeID + "' "; Query += "AND TYPE = '5'"; I then use SqlCommand Command = new SqlCommand(Query, Connection) and SqlDataReader Reader = Command.ExecuteReader() to read in the data. This is taking over a minute to execute from C#, but is much quicker in SSMS. I see from google searching you can do something with CompiledQuery, but I'm confused whether I can still use the built in SQL functions YEAR, MONTH, DAY, and GETDATE. If anyone can show me an example of how to create and call a compiled query using the built in functions, I will be very grateful! Thanks in advance.

    Read the article

  • JavaScript Metaprogramming: Reduce boilerplate of adding functions to a function queue

    - by thurn
    I'm working with animation in JavaScript, and I have a bunch of functions you can call to add things to the animation queue. Basically, all of these functions look like this: function foo(arg1, arg2) { _eventQueue.push(function() { // actual logic } } I'm wondering now if it would be possible to cut down on this boilerplate a little bit, though, so I don't need that extra "_eventQueue" line in the function body dozens of times. Would it be possible, for example, to make a helper function which takes an arbitrary function as an argument and returns a new function which is augmented to be automatically added to the event queue? The only problem is that I need to find a way to maintain access to the function's original arguments in this process, which is... complicated.

    Read the article

  • Effects of the `extern` keyword on C functions

    - by Elazar Leibovich
    In C I did not notice any effect of the extern keyword used before function declaration. At first I thougth that when defining extern int f(); in a single file forces you to implement it outside of the files scope, however I found out that both extern int f(); int f() {return 0;} And extern int f() {return 0;} Compiles just fine, with no warnings from gcc. I used gcc -Wall -ansi, he wouldn't even accept // comments. Are there any effects for using extern before function definitions? Or is it just an optional keyword with no side effects for functions. In the latter case I don't understand why did the standard designers chose to litter the grammar with superfluous keywords. EDIT: to clarify, I know there's usage for extern in variables, but I'm only asking about extern in functions.

    Read the article

  • Defining functions and if statement problems

    - by David Fairbairn
    I'm having a problem with two functions and an if statement. I'm being told the functions go and postcodeChange are not defined. I'm also being told flag is an unexpected identifier at if flag == 1. Any idea where I am going wrong? Thank you. function postcodeChange(){ document.getElementById("goButton").onclick = distanceCheck; } function distanceCheck(){ var distance = document.getElementById("distance").value var patt1=new RegExp("^[0-9]+(\.[0-9]{1})?$"); var out = patt1.exec(distance); if (out == null) { //distance is not a valid number document.getElementById("distanceFlag").value = 1 } else { //distance is valid number document.getElementById("distanceFlag").value = 0 } function go(){ var flag = document.getElementById("distanceFlag").value if flag == 1 { alert("Distance is not valid- enter a number with no more than one decimal point"); } else{ popSubmit('#fa Care Provider Search Go','','0'); } }

    Read the article

  • Question about DBD::CSB Statement-Functions

    - by sid_com
    From the SQL::Statement::Functions documentation: Function syntax When using SQL::Statement/SQL::Parser directly to parse SQL, functions (either built-in or user-defined) may occur anywhere in a SQL statement that values, column names, table names, or predicates may occur. When using the modules through a DBD or in any other context in which the SQL is both parsed and executed, functions can occur in the same places except that they can not occur in the column selection clause of a SELECT statement that contains a FROM clause. # valid for both parsing and executing SELECT MyFunc(args); SELECT * FROM MyFunc(args); SELECT * FROM x WHERE MyFuncs(args); SELECT * FROM x WHERE y < MyFuncs(args); # valid only for parsing (won't work from a DBD) SELECT MyFunc(args) FROM x WHERE y; Reading this I would expect that the first SELECT-statement of my example shouldn't work and the second should but it is quite the contrary. #!/usr/bin/env perl use warnings; use strict; use 5.010; use DBI; open my $fh, '>', 'test.csv' or die $!; say $fh "id,name"; say $fh "1,Brown"; say $fh "2,Smith"; say $fh "7,Smith"; say $fh "8,Green"; close $fh; my $dbh = DBI->connect ( 'dbi:CSV:', undef, undef, { RaiseError => 1, f_ext => '.csv', }); my $table = 'test'; say "\nSELECT 1"; my $sth = $dbh->prepare ( "SELECT MAX( id ) FROM $table WHERE name LIKE 'Smith'" ); $sth->execute (); $sth->dump_results(); say "\nSELECT 2"; $sth = $dbh->prepare ( "SELECT * FROM $table WHERE id = MAX( id )" ); $sth->execute (); $sth->dump_results(); outputs: SELECT 1 '7' 1 rows SELECT 2 Unknown function 'MAX' at /usr/lib/perl5/site_perl/5.10.0/SQL/Parser.pm line 2893. DBD::CSV::db prepare failed: Unknown function 'MAX' at /usr/lib/perl5/site_perl/5.10.0/SQL/Parser.pm line 2894. [for Statement "SELECT * FROM test WHERE id = MAX( id )"] at ./so_3.pl line 30. DBD::CSV::db prepare failed: Unknown function 'MAX' at /usr/lib/perl5/site_perl/5.10.0/SQL/Parser.pm line 2894. [for Statement "SELECT * FROM test WHERE id = MAX( id )"] at ./so_3.pl line 30. Could someone explaine me this behavior?

    Read the article

  • Refreshing metadata on user functions t-SQL

    - by luckyluke
    I am doing some T-SQL programming and I have some Views defines on my database. The data model is still changing these days and I have some table functions defined. Sometimes i deliberately use select * from MYVIEW in such a table function to return all columns. If the view changes (or table) the function crashes and I need to recompile it. I know it is in general good thing so that it prevents from hell lotta errors but still... Is there a way to write such functions so the dont' blow up in my face everytime I change something on the underlying table? Or maybe I am doing something completely wrong... Thanks for help

    Read the article

  • Accessing functions in a parent controller

    - by meridimus
    I have made a ViewController in XCode for an iPhone project I'm working on, but I have a question about nested ViewControllers and what the best way to access a parents ViewController functions? Essentially, at the moment I have a SwitchViewController with MenuViewController (nested) and GameViewController (nested, which renders OpenGL ES). At the moment, I have animated view switching controlled in the SwitchViewController which works. But I want to call it after a player has selected the level from the MenuViewController and run the appropriate level in GameViewController. Not rocket science, I know. What's the best way to call parent functions?

    Read the article

  • Order of calls to set functions when invoking a flex component

    - by Jason
    I have a component called a TableDataViewer that contains the following pieces of data and their associated set functions: [Bindable] private var _dataSetLoader:DataSetLoader; public function get dataSetLoader():DataSetLoader {return _dataSetLoader;} public function set dataSetLoader(dataSetLoader:DataSetLoader):void { trace("setting dSL"); _dataSetLoader = dataSetLoader; } [Bindable] private var _table:Table = null; public function set table(table:Table):void { trace("setting table"); _table = table; _dataSetLoader.load(_table.definition.id, "viewData", _table.definition.id); } This component is nested in another component as follows: <ve:TableDataViewer width="100%" height="100%" paddingTop="10" dataSetLoader="{_openTable.dataSetLoader}" table="{_openTable.table}"/> Looking at the trace in the logs, the call to set table is coming before the call to set dataSetLoader. Which is a real shame because set table() needs dataSetLoader to already be set in order to call its load() function. So my question is, is there a way to enforce an order on the calls to the set functions when declaring a component?

    Read the article

  • Generating an array of functions?

    - by Wordpressor
    I have a few PHP files filled with multiple functions. Let's call them functions1.php, functions2.php, functions3.php: function function_something( $atts ) { extract( something_atts( array( 'foo' => 'bar', 'bar' => 'foo, ), $atts ) ); return 'something'; } I'm loading these files within all_functions.php like this: require_once('functions1.php'); require_once('functions2.php'); require_once('functions3.php'); I'm wondering if it's possible to create an array of all these functions and their attributes? I'm thinking about something like: function my_functions() { require_once('functions1.php'); require_once('functions2.php'); require_once('functions3.php'); } And then some foreach loop, but I'm not sure how should it look like after all. I know this probably looks tricky, but I'm just curious if I'm able to list all my WordPress shortcodes without PHP's Reflection API :)

    Read the article

  • I want to create a common unit test function to check all functions based on parameter

    - by Nilesh Rathod
    I want to create a common unit test function to check all functions based on parameter for e.g commonmethod(string methodname,string paramter1,....) { .... } what logic should i write inside this method so that by passing a actual function in parameter methodname and then the common method should execute that function and should return the output. i am using entity framework for all functions which has been created in my project and now i dont want to create a separate unit test function for each function.just one function should do the job based on different parameters... is that possible.. ?, if so then please provide me an code for same.. Thanks in advance..!!!

    Read the article

  • Jquery: Calling functions from different documents

    - by Tom
    Hi, I've got some Jquery functions that I keep in a "custom.js" file. On some pages, I need to pass PHP variables to the Jquery so some Jquery bits need to remain in the HTML documents. However, as I'm now trying to refactor things to the minimum, I'm tripping over the following: If I put this in my custom.js: $(document).ready(function() { function sayHello() { alert("hello"); } } And this in a HTML document: <script type="text/javascript"> $(document).ready(function() { sayHello(); }); </script> ... the function doesn't get called. However, if both are placed in the HTML document, the function works fine. Is there some kind of public property I need to declare for the function or how do I get Jquery functions in my HTML to talk to external .js files? They're correctly included and work fine otherwise. Thanks.

    Read the article

  • Algorithm Question Maximize Average of Functions

    - by paradoxperfect
    Hello, I have a set of N functions each denoted by Fi(h). Each function returns some value when given an h. I'm trying to figure out a way to maximize the average of all of the functions given some total H value. For example, say each function represents a grade on an assignment. If I spend h hours on assignment i, I will get g = Fi(h) as my grade. I'm given H hours to finish all of the assignments. I want to maximize my average grade for all assignments. Can anyone point me in the right direction to figure this out?

    Read the article

  • Fixing javascript Array functions in Internet Explorer (indexOf, forEach, etc)

    - by Chas Emerick
    As detailed elsewhere, and otherwise apparently well-known, Internet Explorer (definitely 7, and in some instances, 8) do not implement key functions, in particular on Array (such as forEach, indexOf, etc). There are a number of workarounds here and there, but I'd like to fold a proper, canonical set of implementations into our site rather than copy and paste or hack away at our own implementations. I've found js-methods, which looks promising, but thought I'd post here to see whether another library comes more highly-recommended. A couple of misc. criteria: the lib should just be a no-op for those functions that a browser already has implementations for (js-methods appears to do quite well here) non-GPL, please, though LGPL is acceptable

    Read the article

  • C++ vtable resolving with virtual inheritance

    - by Tomas Cokis
    I was curious about C++ and virtual inheritance - in particular, the way that vtable conflicts are resolved between bass and child classes. I won't pretend to understand the specifics on how they work, but what I've gleamed so far is that their is a small delay caused by using virtual functions due to that resolution. My question then is if the base class is blank - ie, its virtual functions are defined as: virtual void doStuff() = 0; Does this mean that the resolution is not necessary, because there's only one set of functions to pick from? Forgive me if this is an stupid question - as I said, I don't understand how vtables work so I don't really know any better.

    Read the article

  • ASP.Net Architecture Specific to Shared/Static functions

    - by Maxim Gershkovich
    Hello All, Could someone please advise in the context of a ASP.Net application is a shared/static function common to all users? If for example you have a function Public shared function GetStockByID(StockID as Guid) as Stock Is that function common to all current users of your application? Or is the shared function only specific to the current user and shared in the context of ONLY that current user? So more specifically my question is this, besides database concurrency issues such as table locking do I need to concern myself with threading issues in shared functions in an ASP.Net application? In my head; let’s say my application namespace is MyTestApplicationNamespace. Everytime a new user connects to my site a new instance of the MyTestApplicationNamespace is created and therefore all shared functions are common to that instance and user but NOT common across multiple users. Is this correct?

    Read the article

  • Change default Console I/O functions handle.

    - by b-gen-jack-o-neill
    Hello. Is it possible to somehow change standart I/O functions handle on Windows? Language preffered is C++. If I understand it right, by selecting console project, compiler just pre-allocate console for you, and operates all standart I/O functions to work with its handle. So, what I want to do is to let one Console app actually write into another app Console buffer. I though that I could get first´s Console handle, than pass it to second app by a file (I don´t know much about interprocess comunication, and this seems easy) and than somehow use for example prinf with the first app handle. Can this be done? I know how to get console handle, but I have no idea how to redirect printf to that handle. Its just study-purpose project to more understand of OS work behind this. I am interested in how printf knows what Console it is assiciated with.

    Read the article

  • using operators and functions for sql report charts (visual studio 2010)

    - by user1682566
    I want to create some charts using sql reporting services. But i am unable to use a lot of functions and operators in combination with my data-fields the following work(Stroke-data type is decimal): > =Fields!Stroke.Value > =Sum(Fields!Stroke.Value) > =First(Fields!Stroke.Value) > =Last(Fields!Stroke.Value) > =2+2394.12 the following dont work: > =Fields!Stroke.Value + 2 > =CStr(Fields!Stroke.Value) > =CDbl(Fields!Stroke.Value) > =Fields!Stroke.Value / Fields!Stroke.Value > =Sum(Fields!Stroke.Value) * 2 all other operators and functions(using Fields!Stroke.Value) dont work too

    Read the article

  • String Functions in IIS Url Rewritting Module

    - by Nariman
    The IIS URL Rewrite Module ships with 3 built-in functions: * ToLower - returns the input string converted to lower case. * UrlEncode - returns the input string converted to URL-encoded format. This function can be used if the substitution URL in rewrite rule contains special characters (for example non-ASCII or URI-unsafe characters). * UrlDecode - decodes the URL-encoded input string. This function can be used to decode a condition input before matching it against a pattern. The functions can be invoked by using the following syntax: {function_name:any_string} The question is: can this list be extended by introducing a Replace function that's available for changing values within a rewrite rule action or condition?

    Read the article

  • Having trouble wrapping functions in the linux kernel

    - by Corey Henderson
    I've written a LKM that implements Trusted Path Execution (TPE) into your kernel: https://github.com/cormander/tpe-lkm I run into an occasional kernel OOPS (describe at the end of this question) when I define WRAP_SYSCALLS to 1, and am at my wit's end trying to track it down. A little background: Since the LSM framework doesn't export its symbols, I had to get creative with how I insert the TPE checking into the running kernel. I wrote a find_symbol_address() function that gives me the address of any function I need, and it works very well. I can call functions like this: int (*my_printk)(const char *fmt, ...); my_printk = find_symbol_address("printk"); (*my_printk)("Hello, world!\n"); And it works fine. I use this method to locate the security_file_mmap, security_file_mprotect, and security_bprm_check functions. I then overwrite those functions with an asm jump to my function to do the TPE check. The problem is, the currently loaded LSM will no longer execute the code for it's hook to that function, because it's been totally hijacked. Here is an example of what I do: int tpe_security_bprm_check(struct linux_binprm *bprm) { int ret = 0; if (bprm->file) { ret = tpe_allow_file(bprm->file); if (IS_ERR(ret)) goto out; } #if WRAP_SYSCALLS stop_my_code(&cs_security_bprm_check); ret = cs_security_bprm_check.ptr(bprm); start_my_code(&cs_security_bprm_check); #endif out: return ret; } Notice the section between the #if WRAP_SYSCALLS section (it's defined as 0 by default). If set to 1, the LSM's hook is called because I write the original code back over the asm jump and call that function, but I run into an occasional kernel OOPS with an "invalid opcode": invalid opcode: 0000 [#1] SMP RIP: 0010:[<ffffffff8117b006>] [<ffffffff8117b006>] security_bprm_check+0x6/0x310 I don't know what the issue is. I've tried several different types of locking methods (see the inside of start/stop_my_code for details) to no avail. To trigger the kernel OOPS, write a simple bash while loop that endlessly starts a backgrounded "ls" command. After a minute or so, it'll happen. I'm testing this on a RHEL6 kernel, also works on Ubuntu 10.04 LTS (2.6.32 x86_64). While this method has been the most successful so far, I have tried another method of simply copying the kernel function to a pointer I created with kmalloc but when I try to execute it, I get: kernel tried to execute NX-protected page - exploit attempt? (uid: 0). If anyone can tell me how to kmalloc space and have it marked as executable, that would also help me solve the above problem. Any help is appreciated!

    Read the article

< Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >