Why is the size of a function in C always 1 byte?

It’s a constraint violation, and your compiler should diagnose it. If it compiles it in spite of that, your program has undefined behaviour [thanks to @Steve Jessop for the clarification of the failure mode, and see @Michael Burr’s answer for why some compilers allow this]: From C11, 6.5.3.4./1: The sizeof operator shall not be applied … Read more

Size of array after a deallocate

This is a question crying out for a canonical one, really. In the interest of answering your specific question in the absence (as far as I can tell, but I may write one eventually), I’ll answer. The argument to size must not be an unallocated allocatable variable. For your code fred is an allocatable variable. … Read more

How can I change the size of an array in C?

You can’t. This is normally done with dynamic memory allocation. // Like “ENEMY enemies[100]”, but from the heap ENEMY* enemies = malloc(100 * sizeof(ENEMY)); if (!enemies) { error handling } // You can index pointers just like arrays. enemies[0] = CreateEnemy(); // Make the array bigger ENEMY* more_enemies = realloc(enemies, 200 * sizeof(ENEMY)); if (!more_enemies) … Read more

Node.js: how to limit the HTTP request size and upload file size?

Just an update (07-2014), as I’m not able to add comments: As correctly noted above, newer Express versions have deprecated the use of the limit middleware and now provide it as a built-in option for the BodyParser middleware: var express = require(‘express’) var bodyParser = require(‘body-parser’) var app = express() app.use(bodyParser.json({ limit: ‘5mb’ }))

How can I set size of a button?

The following bit of code does what you ask for. Just make sure that you assign enough space so that the text on the button becomes visible JFrame frame = new JFrame(“test”); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(4,4,4,4)); for(int i=0 ; i<16 ; i++){ JButton btn = new JButton(String.valueOf(i)); btn.setPreferredSize(new Dimension(40, 40)); panel.add(btn); } … Read more

Java PriorityQueue with fixed size

que.add(d); if (que.size() > YOUR_LIMIT) que.poll(); or did I missunderstand your question? edit: forgot to mention that for this to work you probably have to invert your comparTo function since it will throw away the one with highest priority each cycle. (if a is “better” b compare (a, b) should return a positvie number. example … Read more