|
|
Up |
  |
|
|
  |
Author: sanemansaneman
Date: Apr 30, 2008 06:03
In the below code the last call to myprint does not work (gives a
segmentation error).
But I thought that pointer variables local in main (or any other
function) would first be deleted when the calling function returns. Why
does it give a segmentation fault?
#include
#include
void myprint(double* a) {
printf("number is = %%f\n",*a);
}
int main() {
/* Working! (static allocation) */
double d1 = 1.1;
myprint(&d1);
/* Working! (dynamic allocation) */
double* d2 = (double*) malloc(sizeof(double*));
*d2 = 2.2;
myprint(d2);
|
| Show full article (0.72Kb) |
|
| |
29 Comments |
|
  |
Author:
Date: Apr 29, 2008 05:41
How do I find the length of strings within an array at compile time?
The following is not safe:
const char* MyStrings[] =
{
"one",
"two",
"three",
"end marker"
}
#define StringLength(index) MyStrings[index+1] - MyStrings[index]
Since the strings may not be placed consecutively, or in order, within
memory.
Also
#define String1 "one"
#define String2 "two"
#define String3 "three"
|
| Show full article (0.65Kb) |
|
5 Comments |
|
  |
Author: Jon SargeantJon Sargeant
Date: Apr 19, 2008 22:14
Hi,
I'm looking for a general purpose way of initializing a floating-point
constant with an arbitrary bit pattern using C99. For example,
const unsigned int x=0x3f800000U; //assume 32-bits
const float y=*(float*)&x; //assume 32-bit single-precision IEEE754
Compiling this code on GCC generates the error "initializer element is
not constant". C99 hex floats are a partial solution. I can enter
plus/minus zero, finites, infinites (using 1.0/0.0 and -1.0/0.0), but
NaNs have me stumped. How do I get a constant NaN with a specific
payload? nan() looked promising until I realized that it returns a
variable. Any ideas?
Thanks,
Jon
|
| |
|
15 Comments |
|
  |
|
|
  |
|
|
  |
Author: Hans PoschHans Posch
Date: Mar 4, 2008 01:39
Hi
Ich sollte einen Datenfilter implementieren und dazu liegen die Signale
als File vor. Abhaengig vom Parameter N, nehme ich nun jeweils N
aufeinanderfolgende Signalwerte und bilde aus diesen den Mittelwert um
den entsprechenden gefilterten Wert zu berechnen. Danach verwerfe ich
das älteste Datensignal und nehme den naechsten Wert im File und
berechne den Mittelwert erneut usw.
Die einfachste Sache die zu loesen, waere wohl das gesamte File in ein
Array einzulesen, das ich ja dynamisch allokieren kann. Danach kann ich
mit 2 Schleifen jeweils den Mittelwert bilden. Waere es vielleicht
besser nur ein Array der groesse N zu haben und dort dann immer das
erste Element zu loeschen, die restlichen N-1 Elemente um eins nach oben
zu ruecken und dann einen neuen Wert ins Array lesen? Braeuchte wohl
weniger Memory ;)
Danke fuer Tips!
|
| |
|
1 Comment |
|
  |
|
|
  |
Author: MikeCMikeC
Date: Feb 29, 2008 12:57
If this is on the DOS window of a PC, try looking at the help for
findfirst() and findnext(), which give example programs that can be twisted
to do what you want.
Another function is ftw() {file tree walk}, which is designed to do exactly
what you want. There is a good example program in the help files.
If you are using RHIDE, enter Alt-H for help, C for C- help, A for
Alphabetical list, and run down the list till you get to the entries
mentioned.
MikeC
|
| Show full article (1.00Kb) |
|
2 Comments |
|
  |
|
  |
Author: SarasonSarason
Date: Feb 26, 2008 07:21
Daniel.C wrote:
> Hello,
> What book(s) should you recommend for an absolute beginner ?
> Regards.
> Daniel
>
>
I have a heap of C and C++ books, as I am teaching myself. the one that
makes C clear is "A Book on C" by Kelley and Pohl. For C++ for C
programmers by Pohl.
Both books are thin ,have simple worked examples for every thing that is
taught and are not turgid like a lot of C Books and references.
|
| |
|
no comments
|
|
|
|
|