int main(int argc, const char * argv[]) { int times = 5; char ch = '!'; float f = 6.0; pound(times); pound(ch); pound((int)f); return 0; }
int main(void){ int times = 5; char ch = '!'; float f = 6.0; pound(times); pound(ch); pound((int)f); return 0; }
int main(void) { int times = 5; char ch = '!'; //ANSI码值为33 float f = 6.0; pound(times); //int参数 pound(ch); //char参数自动转换为int类型 pound((int)f);//指派运算符把f强制转换为int类型 return 0; }
int main(void) { int times = 5; char ch = '!'; // ASCII code is 33 float f = 6.0f; pound(times); // int argument pound(ch); // same as pound((int)ch); pound(f); // same as pound((int)f); return 0; }
int main(void) { int times = 5; char ch = '!'; // ASCII码是33 float f = 6.0f; pound(times); // int 类型的参数 pound(ch); // 和pound((int)ch);相同 pound(f); // 和pound((int)f);相同 return 0; }
int main(void) { int times = 5; char ch = '!'; /* ASCII code is 33 */ float f = 6.0; pound(times); /* int argument */ pound(ch); /* char automatically -> int */ pound((int) f); /* cast forces f -> int */ return 0; }
int main(void) { int times = 5; char ch = '!'; /* ASCII code for ! is 3 */ float f = 6.0f; printf("\n\n"); /* Blank lines for readability */ pound( times ); /* int argument */ pound( ch ); /* same as pound( (int)ch ) */ pound( f ); /* same as pound( (int)f ) */ printf("\n\n"); /* Blank lines for readability */ return 0; }
int main(int argc, char **argv) { int32 note=DEFAULT_NOTE, root=DEFAULT_ROOT, verbosity=0, samplerate=-1, datasize=-1, junklength, c; int infd=STDIN_FILENO; unsigned char thing[4096], *point, modes=0; #ifdef __MACOS__ mac_main_wav2pat(&root, ¬e, &infd); #else while ((c=getopt(argc, argv, "r:n:vh"))>0) switch(c) { case 'r': root=atol(optarg); break; case 'n': root=freq_table[atoi(optarg) & 127]; break; case 'u': note=atol(optarg); break; case 'v': verbosity++; break; case 'h': usage(); return 0; default: return 1; } if (optind==argc-1) { if ((infd=open(argv[optind], O_RDONLY))<0) { perror("wav2pat: I can't open your WAVE"); return 3; } } else if (optind!=argc) { usage(); return 1; } #endif /* check out the putative RIFF WAVE on stdin */ if (read(infd, thing, 12)<=0) { perror("wav2pat: I can't read your WAVE"); return 3; } if (memcmp(thing, "RIFF", 4) || memcmp(thing+8, "WAVE", 4)) { fprintf(stderr, "wav2pat: I want a RIFF WAVE on stdin!" NLS); return 2; } while (datasize==-1) { if (read(infd, thing, 8)!=8) { perror("wav2pat: " "Your WAVE ran out before I got to the interesting bits"); return 3; } junklength=LE_LONG(*((int32 *)(thing+4))); /* This Microsoft file format is designed to be impossible to parse correctly if one doesn't have the full specification. If you have a wave with an INFO "chunk", you lose. Thank you for playing. */ if (!memcmp(thing, "fmt ", 4)) { if (junklength > 4096) { fprintf(stderr, "wav2pat: " "WAVEs with %ld-byte format blocks make me throw up!" NLS, junklength); return 2; } if (read(infd, thing, junklength) != junklength) { perror("wav2pat: Your WAVE is mangled"); return 3; } if (LE_SHORT(*((int16 *)(thing))) != 1) { fprintf(stderr, "wav2pat: I don't understand your WAVE. " "It has a type %d format chunk!" NLS, LE_SHORT(*((int16 *)(thing)))); return 2; } if (LE_SHORT(*((int16 *)(thing + 2))) != 1) { fprintf(stderr, "wav2pat: This WAVE has %d channels! " "There can be only one!" NLS, LE_SHORT(*((int16 *)(thing + 2)))); return 2; } samplerate=LE_LONG(*((int32 *)(thing + 4))); switch(LE_SHORT(*((int16 *)(thing + 14)))) { case 8: modes |= MODES_UNSIGNED; break; case 16: modes |= MODES_16BIT; break; default: fprintf(stderr, "wav2pat: Ack! Ppthbth! %d-bit samples!", LE_SHORT(*((int16 *)(thing + 14)))); return 2; } if (verbosity) fprintf(stderr, "wav2pat: This is a %d-bit, %ld Hz WAVE" NLS, (LE_SHORT(*((int16 *)(thing + 14)))), samplerate); } else if (!memcmp(thing, "data", 4)) { if (samplerate==-1) { fprintf(stderr, "wav2pat: Your WAVE has no format information before data!" NLS); return 2; } if (verbosity) fprintf(stderr, "wav2pat: It has %ld bytes of data" NLS, junklength); datasize=junklength; } else { if (verbosity) fprintf(stderr, "wav2pat: " "Your WAVE has a %ld-byte chunk called `%4.4s'" NLS, junklength, thing); /* It's cool to pad chunks with NULs to align them on half-word boundaries. */ if (junklength & 1) junklength++; while (junklength>0) { if ((c=read(infd, thing, (junklength>4096) ? 4096 : junklength)) <= 0) { perror("wav2pat: Now your WAVE has run out of data"); return 3; } junklength -= c; } } } /* hammer together something that looks like a GUS patch header */ #define pound(a) *point++=(a); #define pounds(a) { int16 x = (int16)LE_SHORT(a); memcpy(point, &x, 2); point+=2; } #define poundl(a) { int32 x = LE_LONG(a); memcpy(point, &x, 4); point+=4; } #define bounce(a) point += a; memset(thing, 0, 335); point=thing; /* header */ memcpy(point, "GF1PATCH110", 12); point += 12; /* Gravis ID */ memcpy(point, "ID#000002", 10); point += 10; /* description */ strcpy((char *)point, "Copyleft 1995 EWE&U Conductions and one Retreated Gravi\032"); point += 60; pound(1); /* instruments */ pound(14); /* voices */ pound(0); /* channels */ pounds(1); /* waveforms */ pounds(127); /* master volume */ poundl(datasize); /* data size */ bounce(36); /* reserved */ pounds(1); /* instrument # */ strcpy((char *)point, "Bleahnoise"); /* instrument name */ point += 16; poundl(datasize); /* instrument size */ pound(1); /* layers */ bounce(40); /* reserved */ pound(0); /* layer duplicate */ pound(0); /* layer */ poundl(datasize); /* layer size */ pound(1); /* samples */ bounce(40); /* reserved */ strcpy((char *)point, "bleah"); /* wave name */ point += 7; pound(0); /* fractions */ poundl(datasize); /* wave size */ poundl(0); /* loop start */ poundl(datasize); /* loop end */ pounds(samplerate); /* sample rate */ poundl(8176); /* low freq */ poundl(12543854); /* high freq */ poundl(root); /* root freq */ pounds(512); /* tune */ pound(7); /* balance */ pound(63); /* envelope rates */ pound(63); pound(63); pound(63); pound(63); pound(63); pound(240); /* envelope offsets */ pound(240); pound(240); pound(240); pound(240); pound(240); pound(0); /* tremolo sweep */ pound(0); /* tremolo rate */ pound(0); /* tremolo depth */ pound(0); /* vibrato sweep */ pound(0); /* vibrato rate */ pound(0); /* vibrato depth */ pound(modes); /* modes */ pounds(note); /* scale freq */ pounds(1024); /* scale factor */ bounce(36); /* reserved */ write(STDOUT_FILENO, thing, 335); /* wave data */ while (datasize>0) { if ((c=read(infd, thing, (datasize>4096) ? 4096 : datasize)) <= 0) { perror("wav2pat: I can't read data"); return 3; } write(STDOUT_FILENO, thing, c); datasize -= c; } /* be courteous */ if (infd != STDIN_FILENO) close(infd); return 0; }