Search Results

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

Page 254/364 | < Previous Page | 250 251 252 253 254 255 256 257 258 259 260 261  | Next Page >

  • Any good idioms for error handling in straight C programs?

    - by Will Hartung
    Getting back in to some C work. Many of my functions look like this: int err = do_something(arg1, arg2, arg3, &result); With the intent the result gets populated by the function, and the return value is the status of the call. The darkside is you get something naive like this: int err = func1(...); if (!err) { err = func2(...); if (!err) { err = func3(...); } } return err; I could macro it I suppose: #define ERR(x) if (!err) { err = (x) } int err = 0; ERR(func1(...)); ERR(func2(...)); ERR(func3(...)); return err; But that only works if I'm chaining function calls, vs doing other work. Obviously Java, C#, C++ have exceptions that work very well for these kinds of things. I'm just curious what other folks do and how other folks do error handling in their C programs nowadays.

    Read the article

  • Undefined reference to "func" when compiled with GCC

    - by hotlemontea
    I implement a link list in two files in linklist.h and linklist.c, and I call some functions defined in linklist.h in main function of main.c. linklist.h is included in both linklist.c and main.c. When I compile this program by GCC with Makefile, the error named "undefined reference to xxx" occurs. I think my Makefile is written correctly as below. So what is the possible reason for this linking error CC=gcc CFLAGS= -g -O2 TARGET=target OBJECTS=main.o linklist.o TARGET: $(OBJECTS) $(CC) $(CFLAGS) $(OBJECTS) -o $(TARGET) clean: rm target $(OBJECTS) main.o:linklist.h linklist.o:linklist.h

    Read the article

  • Singly-Linked Lists insert_back and isIncreasing

    - by rezivor
    I just finished writing a program that I can add, remove or print objects to a list, but I am having difficulty implementing two more functions that is insert_back, which inserts a value to the end of a list. Also,I have to modify the representation of a List and alter whatever methods are necessary to make insert_back run in constant time: O(1). This new operation should have the signature: void List::insert_back( const Object& data ); Also, isIncreasing, For example, for a list containing head-() (11) (8) (15) (3), isIncreasing() should return false. However, it would return true when working on a list containing head- () (7) (9) (15). This new operation should have the signature: bool List::isIncreasing() const; Thank you

    Read the article

  • Are sessions modifiable by the client/user?

    - by Sev
    In my PHP Web-App I use sessions to store the user's data. For exmaple, if a user logs in, then an instance of the User class is generated and stored in a Session. I have access levels associated with each user to determine their privileges. Store the user in a session by: $_SESSION['currentUser'] = new User($_POST['username']); For example: if($_SESSION['currentUser'] -> getAccessLevel() == 1) { //allow administration functions } where getAccessLevel() is simply a get method in the User class that returns the _accesslevel member variable. Is this secure? Or can the client somehow modify their access level through session manipulation of some sort?

    Read the article

  • JQuery create new select option

    - by nav
    Hi I have the below functions in regular javascript creating select options. Is there a way I can do this with JQuery without having to use the form object? function populate(form) { form.options.length = 0; form.options[0] = new Option("Select a city / town in Sweden",""); form.options[1] = new Option("Melbourne","Melbourne"); } Below is how I call the function above: populate(document.form.county); //county is the id of the dropdownlist to populate. Many Thanks,

    Read the article

  • Changing the way widgets are rendered/displayed in a form on the template

    - by user334017
    I have a form with a few other embedded forms and some various widgets. The widgets are all saved in an array $form['elements'] and for some of them, I want to display labels and things, but for others I only want to display the basic rendering. foreach($form['elements'] as $elem) echo $elem->render(); this displays everything about the widget. The way it is right now, I couldn't for example call $elem['..'] because the different subforms appear in a random order and have different variable names. I assume I could still put some checks in the template, but it seems easier to fix this in the widget class, like override one of the render functions or something. How would I go about doing this or do you have any links that could help me understand how do do this? on a side note, one of my widgets is the sfWidgetFormChoice and I have no clue where it actually renders or how renderer_classes work

    Read the article

  • What's some simple F# code that generates the .tail IL instruction?

    - by kld2010
    I'd like to see the .tail IL instruction, but the simple recursive functions using tail calls that I've been writing are apparently optimized into loops. I'm actually guessing on this, as I'm not entirely sure what a loop looks like in Reflector. I definitely don't see any .tail opcodes though. I have "Generate tail calls" checked in my project's properties. I've also tried both Debug and Release builds in Reflector. The code I used is from Programming F# by Chris Smith, page 190: let factorial x = // Keep track of both x and an accumulator value (acc) let rec tailRecursiveFactorial x acc = if x <= 1 then acc else tailRecursiveFactorial (x - 1) (acc * x) tailRecursiveFactorial x 1 Can anyone suggest some simple F# code which will indeed generate .tail?

    Read the article

  • using ajax url to call function

    - by Steven Vanerp
    Hopefully I can ask this correctly cuz I know what I want it to do but can't seem to find any answers from searching. I have a func.php page where I have all my functions and I want ajax to use one function from that page. func.php function toptable() { echo"something happens in here"; } index.php <?php include 'func.php'; ?> <script type="text/javascript"> function check_username() { uname=document.getElementById("username").value; var params = "user_id="+uname; var url = "topoftable()"; $.ajax({ type: 'POST', url: url, dataType: 'html', data: params, beforeSend: function() { document.getElementById("right").innerHTML= 'checking' ; }, complete: function() { }, success: function(html) { document.getElementById("right").innerHTML= html ; } }); } </script> Make sense?

    Read the article

  • Initializing a array after declaration

    - by robUK
    Hello, gcc 4.4.3 c89 I have the following code as a sample of what I am trying to do. I don't know the actual size of the array, until I enter the function. However, I don't think I can set the array size after I have declared it. I need it global as some other functions will need to access the device names. Many thanks for any suggestions, /* global */ char *devices_names[]; void fill_devices(size_t num_devices) { devices_names[num_devices]; /* start filling */ }

    Read the article

  • Is there a way to read 10000 lines from a file in python?

    - by windsound
    I am relatively new in python, was working on C a lot. Since I was seeing so many new functions in python that I do not know, I was wondering if there is a function that can request 10000 lines from a file in python. Something like this is what I expect if that kind of function exist: lines = get_10000_lines(file_pointer) Did python have a build-in function or is there any module that I can download for this? If not, how do I do this to be easiest way. I need to analyze a huge file so I want to read 10000 lines and analyze per time to save memory. Thanks for helping!

    Read the article

  • I just don't get why there is a glMatrixMode in OpenGL

    - by René Nyffenegger
    I just don't understand what OpenGL's glMatrixMode is for. As far as I can see, when glMatrixMode(GL_MODELVIEW) is called, it is followed by glVertex, glTranslate, glRotate and the like, that is, OpenGL commands that place some objects somewhere in the space. On the other hand, if glOrtho or glFrustum or gluProjection is called (ie how the placed objects are rendered), it has a preceeding call of glMatrixMode(GL_PROJECTION). I guess what I have written so far is an assumption on which someone will prove me wrong, but is not the point of using different *Matrix Mode*s exactly because there are different kinds of gl-functions: those concerned with placing objects and those with how the objects are rendered? So, if someone could shed some light on this issue, I'd certainly appreciate it.

    Read the article

  • C++ Static Array Initialization - Memory Issue

    - by donalmg
    Hi, I have a header file which contains a member variable declaration of a static char array: class ABC { public: static char newArray[4]; // other variables / functions private: void setArray(int i, char * ptr); } In the CPP file, I have the array initialized to NULL: char ABC::newArray[4] = {0}; In the ABC constructor, I need to overwrite this value with a value constructed at runtime, such as the encoding of an integer: ABC::ABC() { int i; //some int value defined at runtime memset(newArray, 0, 4); // not sure if this is necessary setArray(i,newArray); } ... void setArray(int i, char * value) { // encoding i to set value[0] ... value [3] } When I return from this function, and print the modified newArray value, it prints out many more characters than the 4 specified in the array declaration. Any ideas why this is the case. I just want to set the char array to 4 characters and nothing further. Thanks...

    Read the article

  • How to import .class file in a .java file?

    - by Namratha
    Hi, What i need to do is as follows: I have a bigloo scheme program (*.scm), then using the bigloo frameworks jvm a class file is generated. I want to use this .class file from a .java file. That is, i need to import this(.class) file as i want to use some functions defined in the scheme file which is now a .class file. How do i do it in Eclipse? i have created two packages one for java and one for the .class file. Then i import the package containing the .class file. But i am not able to use the function in the .class file in the .java file. Are there any settings to be done? Please let me know how this can be done.

    Read the article

  • Using template specialization in C++

    - by user550413
    How can I write a function using template specialization that has 2 different input types and an output type: template <class input1, class input2, class output> and return the sum of the 2 numbers (integers/doubles). However, if I get 2 integers I want to return an integer type but for any other combinations of integer and double I'll always return double. I am trying to do that without using directly the '+' operator but having the next functions instead: double add_double_double(double a, double b) {return (a+b);} double add_int_double(int a, double b) {return ((double)(a)+b);} int add_int_int(int a, int b) {return (a+b);}

    Read the article

  • @ symbol for strings in jQuery

    - by anilca
    if (confirm('<%=Ns1.Ns2.MyClass.GetResourceText("DeleteConfirmationMessage")%>')) { /* something to do...*/ } I have a jQuery expression as above. But the return value of GetResourceText method is a very long string. So my page renders the function like below: if (confirm(' Are you sure lablabla? If you delete this lablabla... lablabla... ')) { Because of this my jQuery functions do not work. Is there a symbol for jQuery like @ that we use in C#?

    Read the article

  • Looking for a VIM Book

    - by sixtyfootersdude
    I have been using vim for about six months now. I know my way around pretty well. I know all of the "basic commands", have defined my own functions and have defined some syntax files. I was hopping to pickup a book on vim to read in my spare time. There is nothing specific that I want to learn I just want to improve my general knowledge. I looked on amazon and there are about 7 possibilities. Any recommendations?

    Read the article

  • Processing a method after the view has loaded..

    - by Susanth
    Hi ! I have implemented a subview which is supposed to load immediately when I click a button in the parent view. After loading the subview(which is basically holding an activityindicator), the program is supposed to process a method(which gets data from a server, so takes time) in it. However, I am unable to do it. What happens now is, when I click the button on the parent view, it processes the method first and only after that does the subview load on screen. Why is this so? Is there any specific functions I could use to make my method load only after the view has loaded?

    Read the article

  • How should I use try...except while defining a function?

    - by SpawnCxy
    Hi all, I find I've been confused by the problem that when I needn't to use try..except.For last few days it was used in almost every function I defined which I think maybe a bad practice.For example: class mongodb(object): def getRecords(self,tname,conditions=''): try: col = eval("self.db.%s" %tname) recs = col.find(condition) return recs except Exception,e: #here make some error log with e.message What I thought is ,exceptions may be raised everywhere and I have to use try to get them. And my question is,is it a good practice to use it everywhere when defining functions?If not are there any principles for it?Help would be appreciated! Regards

    Read the article

  • MySQL Integer vs DateTime index

    - by David Kuridža
    Let me start by saying I have looked at many similar questions asked, but all of them relate to Timestamp and DateTime field type without indexing. At least that is my understanding. As we all know, there are certain advantages when it comes to DateTime. Putting them aside for a minute, and assuming table's engine is InnoDB with 10+ million records, which query would perform faster when criteria is based on: DateTime with index int with index In other words, it is better to store date and time as DateTime or UNIX timestamp in int? Keep in mind there is no need for any built-in MySQL functions to be used.

    Read the article

  • Is PThread a good choice for multi-platorm C/C++ multi-threading program?

    - by RogerV
    Been doing mostly Java and smattering of .NET for last five years and haven't written any significant C or C++ during that time. So have been away from that scene for a while. If I want to write a C or C++ program today that does some multi-threading and is source code portable across Windows, Mac OS X, and Linux/Unix - is PThread a good choice? The C or C++ code won't be doing any GUI, so won't need to worry with any of that. For the Windows platform, I don't want to bring a lot of Unix baggage, though, in terms of unix emulation runtime libraries. Would prefer a PThread API for Windows that is a thin-as-possible wrapper over existing Windows threading APIs. ADDENDUM EDIT: Am leaning toward going with boost:thread - I also want to be able to use C++ try/catch exception handling too. And even though my program will be rather minimal and not particularly OOPish, I like to encapsulate using class and namespace - as opposed to C disembodied functions.

    Read the article

  • Writing a C++ wrapper for a C library

    - by stripes
    I have a legacy C library, written in an OO type form. Typical functions are like: LIB *lib_new(); void lib_free(LIB *lib); int lib_add_option(LIB *lib, int flags); void lib_change_name(LIB *lib, char *name); I'd like to use this library in my C++ program, so I'm thinking a C++ wrapper is required. The above would all seem to map to something like: class LIB { public: LIB(); ~LIB(); int add_option(int flags); void change_name(char *name); ... }; I've never written a C++ wrapper round C before, and can't find much advice about it. Is this a good/typical/sensible approach to creating a C++/C wrapper?

    Read the article

  • Call function by pointer and set parametrs in memory block

    - by Ellesmess Glain
    Hi, I've little problem : I'm solving problem with calling function by pointer and passing to it parameters in continuous memory block. My goal is to have function named e.g CallFunc(void * func,void *params, unsigned int param_length); that I'll send function pointer, pointer to function's parameters and eventually parameters length and this calling function will call passed function with it's parameters. I will like write this in C/C++, but if somebody has idea, how this resolve in other language, that supports DLL generation and exportet functions, it will be fine too. Thanks for answers, Ellesmess P.S. I'm sorry about my English, but I'm Czech, thanks :o)

    Read the article

  • What is this (C/C++) program doing?

    - by guitar-
    It's calling these API functions (advapi32.dll) with these parameters: CryptCreateHash ( 3275488, 32771, 0, 0, 1243424 ); CryptHashData ( 3203040, 'UY30930037661', 13, 0 ); CryptCreateHash ( 3276304, 32771, 0, 0, 46463812 ); CryptHashData ( 3203296, '-585164138661', 10, 0 ); CryptCreateHash ( 3276304, 32771, 0, 0, 46463808 ); CryptHashData ( 3203424, '1db17bd8ef8bcbd734424a9eae818907LOGIN OK³·óéB', 40, 0 ); CryptCreateHash ( 3276304, 32771, 0, 0, 46463808 ); CryptHashData ( 3203296, '1db17bd8ef8bcbd734424a9eae818907HWHASH OK', 41, 0 ); Not sure how it would come to 1db17bd8ef8bcbd734424a9eae818907 Anyone have any ideas?

    Read the article

  • (g)Vim with version control like Eclipse

    - by Somebody still uses you MS-DOS
    I was an Eclipse user, now I have to use Vim in my machine. I used to "compare" a file I edited with a CVS repository to do merges an commit the files, using a context menu and my mouse. Is this possible in Vim? Opening a vimdiff for a file before commiting, and commit it from vim itself? And how is that supposed to work? I'm supposing I would be editing a file. Then, I want to see the modifications. I run vimdiff in gvim, and a new window (or buffer) is opened. I run the modifications, save what is applicable (using vimdiff commands), and commit running another command. Is this all transparent in vim? Do I have to keep getting out of vim to my terminal, or can all be done inside it? Do I need to use some plugins, or just really simple functions inside my vimrc?

    Read the article

  • javascript function pointer and "this"

    - by Justin808
    I'm passing a method as a variable to be used as a callback. When its called, the "this" is not the object the method is a member of. How do I go about getting access to the method's object instance so I can get access to it variables and other member functions? I have no control over the callback call method, its a separate library. All I do is call the binding from my object init method. I would have expected this inside my _connection method to have been its object. jsPlumb.bind('connection', this._connection);

    Read the article

< Previous Page | 250 251 252 253 254 255 256 257 258 259 260 261  | Next Page >