Search Results

Search found 48020 results on 1921 pages for 'void return'.

Page 2/1921 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • convert pointer to pointer to void pointer

    - by FihopZz
    When I'm learning to use qsort to sort an array of string, there is a question puzzled me. For example, to sort the following s char *s[] = { "Amit", "Garima", "Gaurav", "Vaibhav" }; To use the qsort, you must provide a comparison function like the following function cstring_cmp I guess in the qsort function, the type of parameter to be passed to the function cstring_cmp is char**. How to convert a char** to a void*? Why can we convert a char** to a void*? int cstring_cmp(const void *a, const void *b) { const char **ia = (const char **)a; const char **ib = (const char **)b; return -strcasecmp(*ia, *ib); /* return the negative of the normal comparison */ }

    Read the article

  • Need for prefixing a function with (void)...

    - by puffadder
    Hi All, I recently came across a rather unusual coding convention wherein the call for a function returning "void" is prefixed with (void). e.g. (void) MyFunction(); Is it any different from the function call like: MyFunction(); Has it got any advantage or is it yet another needless but there coding convention of some sort?

    Read the article

  • C Class Instance from Void Pointer using Ctypes

    - by g.d.d.c
    I've got a C DLL that exposes a handful of methods that return void pointers to a Class like so: void *GetLicense() { static AppLicenseImpl ipds_; return (void *) &ipds_; } In C++, after loading the DLL, I'd do this to work with it: typedef void *(* FPGetLicense)(); GetLicense_ = (FPGetLicense)GetAddress("GetLicense"); license_ = (AppLicense *) GetLicense_(); license_->GetApplicationStatus(); // Load data so that other calls don't fail I can't figure out how to parallel that in Python. This gets me the pointer: d = ctypes.cdll.LoadLibrary('license.dll') d.GetLicense.restype = ctypes.c_void_p p = d.GetLicense() # returns ptr loc, something like 8791433660848L But I obviously can't call p.GetApplicationStatus() in Python. Does anyone have a suggestion on how I'd instantiate that Class the rest of the way in Python so that I can call GetApplicationStatus()?

    Read the article

  • casting unused return values to void

    - by markh44
    int fn(); void whatever() { (void) fn(); } Is there any reason for casting an unused return value to void, or am I right in thinking it's a complete waste of time? Follow up: Well that seems pretty comprehensive. I suppose it's better than commenting an unused return value since self documenting code is better than comments. Personally, I'll turn these warnings off since it's unnecessary noise. I'll eat my words if a bug escapes because of it...

    Read the article

  • returning a Void object

    - by Robert
    What is the correct way to return a Void type, when it isn't a primitive? Eg. I currently use null as below. interface B<E>{ E method(); } class A implements B<Void>{ public Void method(){ // do something return null; } }

    Read the article

  • OpenGl glutIdleFunc(void (*func)(void))

    - by PHENOMERICAN
    I'm trying to design very simple animation in OpenGL such as rotating and translating objects. In the red book, I found that using GLUT's glutIdleFunc() is okay for a simple animation. How many times does glutIdleFunc(...) call the function in one second? Thank you.

    Read the article

  • Scheme: Mysterious void in pattern match.

    - by Schemer
    Hi. I am writing a function called annotate that uses match-lambda -- often with recursive calls to annotate. Here is one of the pattern matches: (`(lambda (,<param1> . ,<params>) ,<stmts>) `(CLOSURE ENV (,<param1> . ,<params>) (lambda (ENV) ,(map annotate (map (lambda (x) (append `(,<param1> . ,<params>) (list x))) `(,<stmts>)))))) However, when this pattern is matched this is what returns: '(CLOSURE ENV (x) (lambda (ENV) ((CLOSURE ENV (x y) (lambda (ENV) ((+ x y)))))) #<void>) Specifically I can't figure out where "void" is coming from. In fact, if I include the line: ,(displayln (map annotate (map (lambda (x) (append `(,<param1> . ,<params>) (list x))) `(,<stmts>)))) it prints: ((CLOSURE ENV (x y) (lambda (ENV) ((+ x y))))) notably without "void". If someone could tell me what the problem is it would be greatly appreciated. Thanks.

    Read the article

  • C++: casting to void* and back

    - by MInner
    * ---Edit - now the whole sourse* When I debug it on the end, "get" and "value" have different values! Probably, I convert to void* and back to User the wrong way? #include <db_cxx.h> #include <stdio.h> struct User{ User(){} int name; int town; User(int a){}; inline int get_index(int a){ return town; } //for another stuff }; int main(){ try { DbEnv* env = new DbEnv(NULL); env->open("./", DB_CREATE | DB_INIT_MPOOL | DB_THREAD | DB_INIT_LOCK | DB_INIT_TXN | DB_RECOVER | DB_INIT_LOG, 0); Db* datab = new Db(env, 0); datab->open(NULL, "db.dbf", NULL, DB_BTREE, DB_CREATE | DB_AUTO_COMMIT, 0); Dbt key, value, get; char a[10] = "bbaaccd"; User u; u.name = 1; u.town = 34; key.set_data(a); key.set_size(strlen(a) + 1 ); value.set_data((void*)&u); value.set_size(sizeof(u)); get.set_flags(DB_DBT_MALLOC); DbTxn* txn; env->txn_begin(NULL, &txn, 0); datab->put(txn, &key, &value, 0); datab->get(txn, &key, &get, 0); txn->commit(0); User g; g = *((User*)&get); printf("%d", g.town); getchar(); return 0; }catch (DbException &e){ printf("%s", e.what()); getchar(); } solution create a kind of "serializator" what would convert all POD's into void* and then will unite these pieces PS Or I'd rewrite User into POD type and everything will be all right, I hope. Add It's strange, but... I cast a defenetly non-pod object to void* and back (it has std::string inside) and it's all right (without sending it to the db and back). How could it be? And after I cast and send 'trough' db defenetly pod object (no extra methods, all members are pod, it's a simple struct {int a; int b; ...}) I get back dirted one. What's wrong with my approach? Add about week after first 'add' Damn... I've compiled it ones, just for have a look at which kind of dirt it returnes, and oh! it's okay!... I can't ! ... AAh!.. Lord... A reasonable question (in 99.999 percent of situations right answer is 'my', but... here...) - whos is this fault? My or VSs?

    Read the article

  • Issue with dynamic array Queue data structure with void pointer

    - by Nazgulled
    Hi, Maybe there's no way to solve this the way I'd like it but I don't know everything so I better ask... I've implemented a simple Queue with a dynamic array so the user can initialize with whatever number of items it wants. I'm also trying to use a void pointer as to allow any data type, but that's the problem. Here's my code: typedef void * QueueValue; typedef struct sQueueItem { QueueValue value; } QueueItem; typedef struct sQueue { QueueItem *items; int first; int last; int size; int count; } Queue; void queueInitialize(Queue **queue, size_t size) { *queue = xmalloc(sizeof(Queue)); QueueItem *items = xmalloc(sizeof(QueueItem) * size); (*queue)->items = items; (*queue)->first = 0; (*queue)->last = 0; (*queue)->size = size; (*queue)->count = 0; } Bool queuePush(Queue * const queue, QueueValue value, size_t val_sz) { if(isNull(queue) || isFull(queue)) return FALSE; queue->items[queue->last].value = xmalloc(val_sz); memcpy(queue->items[queue->last].value, value, val_sz); queue->last = (queue->last+1) % queue->size; queue->count += 1; return TRUE; } Bool queuePop(Queue * const queue, QueueValue *value) { if(isEmpty(queue)) return FALSE; *value = queue->items[queue->first].value; free(queue->items[queue->first].value); queue->first = (queue->first+1) % queue->size; queue->count -= 1; return TRUE; } The problem lies on the queuePop function. When I call it, I lose the value because I free it right away. I can't seem to solve this dilemma. I want my library to be generic and modular. The user should not care about allocating and freeing memory, that's the library's job. How can the user still get the value from queuePop and let the library handle all memory allocs/frees?

    Read the article

  • casting void* to float* creates only zeros

    - by Paperflyer
    I am reading an audio file using CoreAudio (Extended Audio File Read Services). The audio data gets converted to 4-byte float and handed to me as a void* buffer. It can be played with Audio Queue Services, so its content is correct. Next, I want to draw a waveform and thus need access to the actual samples. So, I cast void* audioData to float*: Float32 *floatData = (Float32 *)audioData; When accessing this data however, I only get 0.0 regardless of the index. Float32 value = floatData[index]; // Is always zero for any index Am I doing something wrong with the cast?

    Read the article

  • Sending items in a LINQ sequence to a method that returns void

    - by generalt
    Hello all. Often while I'm dealing with LINQ sequences, I want to send each item to a method returning void, avoiding a foreach loop. However, I haven't found an elegant way to do this. Today, I wrote the following code: private StreamWriter _sw; private void streamToFile(List<ErrorEntry> errors) { if (_sw == null) { _sw = new StreamWriter(Path.Combine (Path.GetDirectoryName(_targetDatabasePath), "errors.txt")); } Func<ErrorEntry, bool> writeSelector = (e) => { _sw.WriteLine(getTabDelimititedLine(e)); return true; }; errors.Select(writeSelector); _sw.Flush(); } As you can see, I write a lambda function that just returns true, and I realize that the Select method will return a sequence of booleans- I'll just ignore that sequence. However, this seems a little bit noobish and jank. Is there any elegant way to do this? Or am I just misapplying LINQ? Thanks.

    Read the article

  • [Objective-C] Primitive question, (void) init method.

    - by user354289
    Hi, I have a question in Objective-C. I'm using init method Apple recommended style. - (id)initMyClass: (int)a { if (self = [super init]) { // a... } return self; } Init method returns own object pointer. Then, if the object will not be refered from any objects, can empty return method(void) be better? - (void)initMyClass: (int)a { if ([super init] != nil) { // a... } } I want to know about that, if init method doesn't return self, what problem will occur?

    Read the article

  • When should a method of a class return the same instance after modifying itself?

    - by modiX
    I have a class that has three methods A(), B() and C(). Those methods modify the own instance. While the methods have to return an instance when the instance is a separate copy (just as Clone()), I got a free choice to return void or the same instance (return this;) when modifying the same instance in the method and not returning any other value. When deciding for returning the same modified instance, I can do neat method chains like obj.A().B().C();. Would this be the only reason for doing so? Is it even okay to modify the own instance and return it, too? Or should it only return a copy and leave the original object as before? Because when returning the same modified instance the user would maybe admit the returned value is a copy, otherwise it would not be returned? If it's okay, what's the best way to clarify such things on the method?

    Read the article

  • sendmail is using return-path instead of from address

    - by magd1
    I have a customer that is complaining about emails marked as spam. I'm looking at the header. It shows the correct From: [email protected] However, it doesn't like the return-path. Return-Path: <[email protected]> Received-SPF: neutral (google.com: x.x.x.x is neither permitted nor denied by domain of [email protected]) client-ip=x.x.x.x; Authentication-Results: mx.google.com; spf=neutral (google.com: x.x.x.x is neither permitted nor denied by domain of [email protected]) [email protected] How do I configure sendmail to use the From address for the Return-Path?

    Read the article

  • Linux Exim set return-path header automaticly using from header

    - by solomongaby
    Hello, I use Exim on a Centos distribution and have some problems with the mail sending. In order to make all the email pass the spam filters the "Return-path" and "Sender" headers have to be attached to each email. What should I do in order to have "Return-path" and "Sender" headers added by Exim to be exactly the same as the "From" header created by my mail client ? Thanks

    Read the article

  • Which statically typed languages support intersection types for function return values?

    - by stakx
    Initial note: This question got closed after several edits because I lacked the proper terminology to state accurately what I was looking for. Sam Tobin-Hochstadt then posted a comment which made me recognise exactly what that was: programming languages that support intersection types for function return values. Now that the question has been re-opened, I've decided to improve it by rewriting it in a (hopefully) more precise manner. Therefore, some answers and comments below might no longer make sense because they refer to previous edits. (Please see the question's edit history in such cases.) Are there any popular statically & strongly typed programming languages (such as Haskell, generic Java, C#, F#, etc.) that support intersection types for function return values? If so, which, and how? (If I'm honest, I would really love to see someone demonstrate a way how to express intersection types in a mainstream language such as C# or Java.) I'll give a quick example of what intersection types might look like, using some pseudocode similar to C#: interface IX { … } interface IY { … } interface IB { … } class A : IX, IY { … } class B : IX, IY, IB { … } T fn() where T : IX, IY { return … ? new A() : new B(); } That is, the function fn returns an instance of some type T, of which the caller knows only that it implements interfaces IX and IY. (That is, unlike with generics, the caller doesn't get to choose the concrete type of T — the function does. From this I would suppose that T is in fact not a universal type, but an existential type.) P.S.: I'm aware that one could simply define a interface IXY : IX, IY and change the return type of fn to IXY. However, that is not really the same thing, because often you cannot bolt on an additional interface IXY to a previously defined type A which only implements IX and IY separately. Footnote: Some resources about intersection types: Wikipedia article for "Type system" has a subsection about intersection types. Report by Benjamin C. Pierce (1991), "Programming With Intersection Types, Union Types, and Polymorphism" David P. Cunningham (2005), "Intersection types in practice", which contains a case study about the Forsythe language, which is mentioned in the Wikipedia article. A Stack Overflow question, "Union types and intersection types" which got several good answers, among them this one which gives a pseudocode example of intersection types similar to mine above.

    Read the article

  • Is it bad to have multiple return statements?

    - by scot
    Hi, I have a code somethg like below: int method(string a ,int b , int c){ if(cond1) return -1; if(cond2 || cond3) return 3; if(cond1 && cond2) return 0; else return -999; } Does it perform badly when compared to having multiple if else and have single return?

    Read the article

  • Java return to position N in call stack.

    - by Finbarr
    Using the return keyword in Java code will return execution to the last piece of calling code in the call stack. If object foo calls baz.bar(), the return keyword in the bar method will continue code execution in foo. Let's say I have object foo that calls foofoo that calls foofoofoo in the above scenario, and foofoofoo calls baz.bar(). Is there anyway in Java to use the return keyword, or something else, so that the code in the bar method can return all the way back up to foo? (WITHOUT THROWING AN EXCEPTION)

    Read the article

  • unable to return 'true' value in C function

    - by Byron
    If Im trying to check an input 5 byte array (p) against a 5 byte array stored in flash (data), using the following function (e2CheckPINoverride), to simply return either a true or false value. But it seems, no matter what I try, it only returns as 'false'. I call the function here: if (e2CheckPINoverride(pinEntry) == 1){ PTDD_PTDD1 = 1; } else{ PTDD_PTDD1 = 0; } Here is the function: BYTE e2CheckPINoverride(BYTE *p) { BYTE i; BYTE data[5]; if(e2Read(E2_ENABLECODE, data, 5)) { if(data[0] != p[0]) return FALSE; if(data[1] != p[1]) return FALSE; if(data[2] != p[2]) return FALSE; if(data[3] != p[3]) return FALSE; if(data[4] != p[4]) return FALSE; } return TRUE; } I have already assigned true and false in the defines.h file: #ifndef TRUE #define TRUE ((UCHAR)1) #endif #ifndef FALSE #define FALSE ((UCHAR)0) #endif and where typedef unsigned char UCHAR; when i step through the code, it performs all the checks correctly, it passes in the correct value, compares it correctly and then breaks at the correct point, but is unable to process the return value of true? please help?

    Read the article

  • Omit return type in C++0x

    - by Clinton
    I've recently found myself using the following macro with gcc 4.5 in C++0x mode: #define RETURN(x) -> decltype(x) { return x; } And writing functions like this: template <class T> auto f(T&& x) RETURN (( g(h(std::forward<T>(x))) )) I've been doing this to avoid the inconvenience having to effectively write the function body twice, and having keep changes in the body and the return type in sync (which in my opinion is a disaster waiting to happen). The problem is that this technique only works on one line functions. So when I have something like this (convoluted example): template <class T> auto f(T&& x) -> ... { auto y1 = f(x); auto y2 = h(y1, g1(x)); auto y3 = h(y1, g2(x)); if (y1) { ++y3; } return h2(y2, y3); } Then I have to put something horrible in the return type. Furthermore, whenever I update the function, I'll need to change the return type, and if I don't change it correctly, I'll get a compile error if I'm lucky, or a runtime bug in the worse case. Having to copy and paste changes to two locations and keep them in sync I feel is not good practice. And I can't think of a situation where I'd want an implicit cast on return instead of an explicit cast. Surely there is a way to ask the compiler to deduce this information. What is the point of the compiler keeping it a secret? I thought C++0x was designed so such duplication would not be required.

    Read the article

  • Method return values and exceptions

    - by dnagirl
    I have an interface called iIncident which defines a single method when(). when() should return a DateTime object. I'm trying to decide what to do if $object->when() has no DateTime to return as might be the case just after an object is instantiated and before all its properties are set. My choices are: return false throw some kind of Exception return some default DateTime like '9999-01-01' My inclination is to go with an Exception since $object really can't act as an incident until it knows when it occurred. I don't want to return a default DateTime because it complicates comparisons and it's not true. And I don't really want to return false because then I have to check for it every time I call the method- but if that is the preferred method, I guess I will. Is throwing an exception the best way? And is there a predefined exception type I should use (none of the SPL ones struck me as particularly appropriate- but that might just indicate my lack of experience)?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >