Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
pseudorandom name
May 6, 2007

Red Oktober posted:

I've tested this by trying to compile simclist into my project as well, and it fails for the same reasons.

Exact error is "error: syntax error before ‘char’" (if char is what I'm trying to declare.)

I'm using gcc 4.0.1, on mac os x leopard.

Any ideas?

The C grammar doesn't allow it.

labeled-statements are composed of labels followed by statements and declarators aren't statements.

You've discovered one ramification of this, another is that things like
code:
void fn()
{
    goto label;
    label:
}
also won't compile while
code:
void fn()
{
    goto label;
    label: [b];[/b]
}
will.

Adbot
ADBOT LOVES YOU

pseudorandom name
May 6, 2007

oldkike posted:

C and C++ are so weird sometimes. Here's another syntax weirdness:
Speaking of weird, nothing tops Duff's Device:
code:
send(to, from, count)
register short *to, *from;
register count;
{
    register n = (count + 7) / 8;
    switch (count % 8) {
    case 0: do { *to = *from++;
    case 7:      *to = *from++;
    case 6:      *to = *from++;
    case 5:      *to = *from++;
    case 4:      *to = *from++;
    case 3:      *to = *from++;
    case 2:      *to = *from++;
    case 1:      *to = *from++;
               } while (--n > 0);
    }
}

pseudorandom name fucked around with this message at 09:17 on Mar 3, 2008

pseudorandom name
May 6, 2007

timer_create()/timer_settime()/etc. are a whole lot more useful than alarm() or setitimer().

pseudorandom name
May 6, 2007

Otto Skorzeny posted:

So does gcc, but at least the latter is kind enough to inform you you're using a deprecated header

The got rid of them over a year ago for 4.3.0's release.

pseudorandom name
May 6, 2007

RussianManiac posted:

is there an explicit call to make a pthread go to sleep, and a call to wake it up?

Yes, many. What are you trying to do?

pseudorandom name
May 6, 2007

Olly the Otter posted:

Are you wanting to force a thread to go to sleep with a function call from a different thread, sort of like the Win32 API function SuspendThread? I'm fairly certain you can't do that with POSIX threads.

Oh, yeah, if that's what you're trying to do, you're on your own.

A quick look at Boehm GC's stop-the-world implementation shows that it stops individual threads using pthread_kill to get them into it's own signal handler that blocks on a semaphore, which seems to be the most portable method.

pseudorandom name
May 6, 2007

teen bear posted:

Could someone tell me why that's happening and also what a backtrace and memory map are?

The backtrace is a listing of called functions on the stack, in reverse order. The memory map is the layout of memory in your program, which can sometimes be useful for finding problems.

Irrelevant problems in your program (all of which are identified if you build with -Wall like you should)
  • argv should be char **argv or char *argv[], not char *argv
  • you're confusing equality (==) and assignment (=)
  • conc is unused
As to the actual root of the crash, what's open the second time through the loop?

pseudorandom name
May 6, 2007

Dijkstracula posted:

Is the C89 standard published in any official capacity online? I can only see places to purchase it from ISO/ANSI.

The final drafts are freely available online.

pseudorandom name
May 6, 2007

Rahu posted:

Thanks for the help, wasn't aware of that.

I assumed gcc was in c89 because it still needs the -std=c99 command line switch for declaring variables in the initialization of a for loop, does it use some mix of the standards by default?

The default is -std=gnu89, which is ISO C90 plus GCC extensions, including several that ended up in C99.

pseudorandom name
May 6, 2007

mincepiesupper posted:

I have a question about debugging vectors: I recently had to change stl header files in order to make the use of the [] operator behave more like at() and tell me when indices went beyond the size of the vector. Is there a way I could have done this without changing the header files? I'm using gcc 4.1.

Also, I wasn't able to get any output which told me where exactly the error was as any assert I added reported the error in the stl header file not the code that was using an invalid index.

#define _GLIBCXX_DEBUG

pseudorandom name
May 6, 2007

mincepiesupper posted:

Will this work with a release build? The code I am having the problem with is not mine, what I've been given to build it with is for release builds only. I've also been told that debug builds don't work but I've not yet tried this to see exactly what 'don't work' means.

If you can change <vector> to hack in your own debugging, you have enough to build with the debug version of libstdc++ instead.

pseudorandom name
May 6, 2007

Vanadium posted:

Come on, there is a billion IO mechanisms that deal in non-terminated data to begin with, so just use fwrite here.

And printf is one of them, so it's not like you have to live without formatted output to make this work.

pseudorandom name
May 6, 2007

Dijkstracula posted:

Well, I stand corrected. I mean, building the format string will be a bit of a kludge, but that's minor compared to what I was thinking he'd have to do beforehand.

printf("%.*s\n", length, str);

pseudorandom name
May 6, 2007

Thornes posted:

I'm trying to write a program in which a bunch of processes(on a linux machine) communicate very simply with a shared integer. No semaphores or any kind of process synchronization is necessary. The problem is I have no idea how to do this and I'm having a hard time finding an easy to understand tutorial.

All I really need is for someone to point me in the right direction by showing me how to create this shared int and how I can read/write to it.

Any help would be appreciated. Thanks goons!

code:
int fd = open("somefile", O_RDWR);

volatile int * sharedInt = mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);

__sync_add_and_fetch(sharedInt, 3);

pseudorandom name
May 6, 2007

Thornes posted:

Well this looks like a good start so thanks for the quick reply but is there a way to do this without having to deal with a file?

mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0); will work if you do it in the parent and use it from fork()ed children.

Edit: Alternately, you can use int fd = shm_open("/somefile", O_RDWR|O_CREAT, S_IRUSR|S_IWUSR) instead of open(). And don't forget to ftruncate(fd, getpagesize()) before the mmap().

pseudorandom name fucked around with this message at 00:46 on Nov 4, 2009

pseudorandom name
May 6, 2007

slovach posted:

I was trying to wrap my head around function pointers in C and came across something.

code:
void dongs(char* name, void (*func)(void*))
{ 
... stuff 
}
dongs("test", func);
I figured I could just use the void* as the argument and cast it to whatever type as needed, but not every function necessarily takes an argument, so it obviously complains if I pass it something like:

code:
void func(void)
{
	printf("butts");
}
It throws a warning but otherwise compiles and works. Is this truly some kind of horror and is there a better way? I think I'm treading on dangerous grounds here SOS send help need advice

Depends on the ABI, but it should work just about everywhere with the normal C calling convention.

pseudorandom name
May 6, 2007

Hiyoshi posted:

I'm implementing a shell for a class project and like all other shells, when pressing CTRL-C, a new prompt is supposed to appear. That's no problem, but how do I stop ^C from displaying in my program when I press it? bash, zsh, ksh, etc. don't display ^C anywhere when it's pressed, they just display a new prompt.

code:
#include <termios.h>
#include <unistd.h>

struct termios termios;

tcgetattr(tty, &termios);

termios.c_lflag &= ~ECHOCTL;

tcsetattr(tty, TCSANOW, &termios);

pseudorandom name
May 6, 2007

Nigglypuff posted:

maybe im missing something here but surely any function that manipulates words and letters is gonna choke if you call it with a picture?

Yes, you're missing something.

pseudorandom name
May 6, 2007

GrumpyDoctor posted:

I have a third-party library that, when it does its thing, writes to stdout. I want it to not do this. It seems like I might be able to use freopen somehow, but I don't know how to redirect stdout to nowhere before I execute the library function (I'm on windows, so no /dev/null) and back to what it was afterward, or even if this is the way to go.

edit: there actually was an option to turn this off squirreled away somewhere, but I'm still curious about whether this is possible

freopen("\\\\.\\Device\\Null", "w", stdout) might work.

pseudorandom name
May 6, 2007

functional posted:

Got it. The magic trick is learning that the sockaddr you get back can be cast to a sockaddr_in if you know it's IPv4. Also, I needed ntohl.

And you can determine what type of sockaddr you have by looking at the sa_family field.

pseudorandom name
May 6, 2007

Contero posted:

At what value do (single) floats lose integer precision?

For IEEE floats, any integer with absolute value less than or equal to 2significand can be represented exactly.

So, for 32-bit floats with a 24-bit significand, 224 = 16777216.

pseudorandom name
May 6, 2007

Signals won't result in truncated disk I/O either.

pseudorandom name
May 6, 2007

LockeNess Monster posted:

Is the layout in memory same as a struct for a class with both public and private members? That is, if I am reading a class from a file or char buffer or something, can I cast that char buffer to be pointer to class and then have a working instance of that class through that pointer?

Yes, but you don't want to do that for other reasons.

pseudorandom name
May 6, 2007

w00tz0r posted:

Does anyone know if Microsoft modified struct in_addr in berkeley sockets for their windows 7 implementation?

I'm trying to join a multicast session, but all the examples I see are using the ip_mreq structure, where in_addr contains a sin_addr as a member.

When I use intellisense on a struct in_addr it only gives me S_un as an option, which I'd noticed was the member inside sin_addr.

I'm going to guess without looking that S_un is a union of a bunch of different sockaddr types, and the member you're looking for may or may not be inside a struct member of that union.

pseudorandom name
May 6, 2007

w00tz0r posted:

For some reason I was interpreting "un" as "unsigned" rather than "union". That makes a lot more sense.

And to follow up, there's probably a #define sin_addr S_un.$SOMETHING.sin_addr in a header somewhere.

pseudorandom name
May 6, 2007

Rocko Bonaparte posted:

Is it possible to break a string literal up across lines with comments in between? I rarely find a need for this, except when working with regular expressions. I'll show you generally what I want to be able to do:

code:
regex re("^(\\d+)"      // Start with one or more numeric digits
	 "\\s+(R)"      // Eventually followed by space with an 'R'
         "\\s+(\\w+)"   // More space and then the ID name
	 );
Otherwise the regular expressions get pretty atrocious. I have to say I appreciate Perl's /x format where one can comment their regular expressions. It's purdy--I swear sometimes it's the only drat purdy thing about that whole language.

Maybe you should compile it and see what happens instead of posting about it on the internet?

pseudorandom name
May 6, 2007

Maybe one day somebody will invent something nice using initialization lists and we can just do something like Format("{0} {2} {1}\n", {3, "stuff", 2.0f})

pseudorandom name
May 6, 2007

FearIt posted:

I'm having some trouble with a C++ project I'm writing that uses ImageMagick to convert images to different formats. The problem is happening with the system() command. When running in the Netbeans debugger I am getting an error saying the "sh: convert: command not found". But when I run the program from the terminal, everything works fine.

example code:
system("convert image1.tif image2.jpg");

I have tried to google the problem, but I cannot seem to find the answer.
Any idea what I am doing wrong?

NetBeans is probably passing a bad $PATH to your program.

Also, you'd almost certainly be better off using the ImageMagick library directly instead of executing the programs yourself.

pseudorandom name
May 6, 2007

The minimum number of bytes is 1.

pseudorandom name
May 6, 2007

ShoulderDaemon posted:

I thought the urgent flag could result in a select indicating data available while there are zero bytes available for a normal read.

That may be possible, but I have no idea how urgent/OOB works and I doubt anybody sensible would be using it in new code.

edit: Also, Linux has a SO_RCVLOWAT, but that only influences select/poll/epoll/etc. since 2.6.28 or so, before that it'll just make read/recv/etc. block until the low water mark is not met (and select/etc. will return readable for any amount of data).

I think Solaris also has a working SO_RCVLOWAT, but everybody else (including Windows) just ignore that socket option.

pseudorandom name fucked around with this message at 05:01 on Aug 11, 2010

pseudorandom name
May 6, 2007

That just tells me how reliable network-facing Microsoft products from the late '90s are.

pseudorandom name
May 6, 2007

roomforthetuna posted:

tldr; how do you make a program crash-dump info in a form that can be turned into a file and line number (and ideally but not necessarily also stack trace)?

http://code.google.com/p/google-breakpad/

pseudorandom name
May 6, 2007

Member-wise assignment, although there's nothing stopping to from just doing a memcpy() if it can get away with it.

(Hooray for the "as-if" rule!)

pseudorandom name
May 6, 2007

You are probably using stack memory after it has been freed (after the function has returned), and the printf() call is overwriting that memory with it's own state.

pseudorandom name
May 6, 2007

Well, that's terrible advice.

pseudorandom name
May 6, 2007

Won't a stack wrapping a vector push/pop from the front of the vector? And require the equivalent of big memmove() for every operation?

edit: Nope, it uses push_back(). You learn something new every day.

pseudorandom name fucked around with this message at 19:57 on Sep 14, 2010

pseudorandom name
May 6, 2007

And you have to keep in my that whomever is sending the message could be lying about the buffer size.

pseudorandom name
May 6, 2007

Getting the source file and line number information would require interpreting the DWARF information, which is much more involved than just figuring out which dynamic symbol (probably) contains the address.

pseudorandom name
May 6, 2007

libbfd doesn't have an ABI, either, which will make your life difficult when you upgrade. (It exists purely to share code between the various components of binutils, not to provide a public library. Not that that stops people from using it anyway, and causing much suffering.)

Adbot
ADBOT LOVES YOU

pseudorandom name
May 6, 2007

http://codepad.org/TuWkRENh

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply