A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a2 + b2 = c2
For example, 32 + 42 = 9 + 16 = 25 = 52.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
Source: http://projecteuler.net/index.php?section=problems&id=9
I tried but didn't know where my code...
hello, can somebody explain me about redefinition in C:
is it possible to do something like this
typedef struct NumberContainer* ptrNumberContainer;
and after that
typedef struct NumberContainer* ptrCall;
may it cause some problems during linkage? thanks in advance
...
Given that I have a pointer to a function (provided by dlsym() for example) and a linked list of typed arguments, how can I construct a C function call with those arguments?
Example:
struct param {
enum type { INT32, INT64, STRING, BOOL } type;
union { int i32; long long i64; char *str; bool b; } value;
struct param *next;
};...
I have following code:
static __inline__ LIST list_List(POINTER P)
{
return list_Cons(P,list_Nil());
}
After compilation I got following warning:
inlining is unlikely but function size may grow
I removed the inline and changed into the following :
static LIST list_List(POINTER P)
{
return list_Cons(P,list_Nil());
}
Now ...
How can I free a const char*? I allocated new memory using malloc, and when I'm trying to free it I always receive the error "incompatible pointer type"
The code that causes this is something like:
char* name="Arnold";
const char* str=(const char*)malloc(strlen(name)+1);
free(str); // error here
...
Unfortunately yes.
I have my shared library compiled, the linker doesn't complain about not finding it but still I get undefined reference error. Thinking that I might be doing something wrong I did a little research and found this nice, simple walkthrough:
http://www.adp-gmbh.ch/cpp/gcc/create_lib.html
which I've followed to the lett...
Hello, I have a very large code, that's why I can't post here all my code, can somebody explain what might be a problem if I have an error incompatible pointer type and give me several ways to solve it, thanks in advance
just small clarification: I'm workin with pointers to functions
ptrLine createBasicLine(){
DECLARE_RESULT_ALLOC...
Hi,
I am trying to work out if I need to call close on a fstream object if the intial open failed.
i.e.
std::fstream strm;
strm.open( "filename" );
if( ! strm.fail() )
{
// Do something
strm.close(); // [1]
}
strm.close(); // [2]
Where should close be called here - should it always be called [2] or only if the open succ...
i'm currently looking through some source code i found on the net, which makes use of preprocessor macros in a way i don't understand. it implements the quad-edge data-structure.
hope, someone can clear things for me!
typedef int edge_ref;
typedef struct {
edge_ref next[4];
void *data[4];
unsigned mark;
} edge_struct;
#def...
Hello all,
in Redis (http://code.google.com/p/redis) there are scores associated to elements, in order to take this elements sorted. This scores are doubles, even if many users actually sort by integers (for instance unix times).
When the database is saved we need to write this doubles ok disk. This is what is used currently:
snprin...
Hi,
I'm developing an application on an embedded linux OS (uClinux) and I need to be able to lock the mutex more than once (by the same thread).
I have a mutex and a mutexattr defined and initialized as follows:
pthread_mutexattr_t waiting_barcode_mutexattr;
pthread_mutex_t waiting_barcode_mutex;
pthread_mutexattr_init(&waiting_barco...
In the embedded system I'm working on, we are using a table of function pointers to support proprietary Dynamic Libraries.
We have a header file that uses named constants (#define) for the function pointer indices. These values are used in calculating the location in the table of the function's address.
Example:
*(export_table.c)...
Hi there,
Its been a while now and im still trying to get a certain code to work. I asked some question about different commands etc. before, but now I hope this is the final one (combining all questions in one code).
I basically want to :
*Scan an input (should be character ? )
*Check if its a number
*If not, return error
*Convert...
While debugging a crash, I came across this issue in some code:
int func()
{
char *p1 = malloc(...);
if (p1 == NULL)
goto err_exit;
char *p2 = malloc(...);
if (p2 == NULL)
goto err_exit;
...
err_exit:
free(p2);
free(p1);
return -1;
}
The problem occurs when the first malloc fails. B...
EDIT: I just found my problem after writing this long post explaining every little detail... If someone can give me a good answer on what I'm doing wrong and how can I get the execution time in seconds (using a float with 5 decimal places or so), I'll mark that as accepted. Hint: The problem was on how I interpreted the clock_getttime() ...
I want to be able to map memory to a file descriptor so I can use some existing functions that need a file descriptor. Here's essentially what I'm looking for:
void do_operation1(int fd);
char data[DATA_MAX] = { /* embedded binary data */ };
int fd = addr_to_fd(data, DATA_MAX);
do_operation1(fd);
/* ... operate on fd ... */
What sy...
Hello everyone,
I've not visited this site with a question, so I'm a bit clumsy with the interface, but here goes...
When I examine the code generated by gcc -v -o proggy.exe proggy.o I find that the command line expands into a large bunch of library options and libraries, all of which are linked using collect2.exe. What happened to ...
I want to do it:
int main () {
bla bla bla
void *onetype;
switch (USER_INPUT_TYPE) {
CASE CONVERT_TO_CHAR:
convert onetype VOID TO CHAR >>> HOW???
CASE CONVERT_TO_INT:
convert onetype VOID TO INT >>> HOW???
LOT OF CASES...
}
}
Yes, I know type casting, but type casting is a 'temporary'...
Our computer science teacher once said that for some reason it is more efficient to count down that count up.
For example if you need to use a FOR loop and the loop index is not used somewhere (like printing a line of N * to the screen)
I mean that code like this :
for (i=N; i>=0; i--)
putchar('*');
is better than:
for (i=0; i<...
Is there a way to get pre-processed C/Objective-C code? I have some files I acquired and would like to see the code produced by some #defines.
...